我的项目中有一个寻呼机标签条,当在模拟器或设备上运行时,它会像这样开始居中
我想要实现的是让标签开始像这样
我已经尝试在我的 xml 中留下布局重力,但这对我不起作用,我无法解决这个问题,这是我的带有寻呼机标签条的 xml。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity" >
<android.support.v4.view.PagerTabStrip
android:layout_width="wrap_content"
android:layout_height="50dp"
android:background="@drawable/gradient_bg"
android:textColor="#fff"
android:textSize="20sp"
android:id="@+id/tab_strip"
android:focusableInTouchMode="false">
</android.support.v4.view.PagerTabStrip>
</android.support.v4.view.ViewPager>
</LinearLayout>
爪哇代码
import android.graphics.Color;
import android.graphics.drawable.AnimationDrawable;
import android.media.MediaPlayer;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.PagerTabStrip;
import android.support.v4.view.ViewPager;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
public class MainActivity extends FragmentActivity {
//adview
ViewPager pager;
PagerTabStrip tab_strp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_tab);
ma_pager_adapter mapager=new ma_pager_adapter(getSupportFragmentManager());
pager=(ViewPager)findViewById(R.id.pager);
pager.setAdapter(mapager);
tab_strp=(PagerTabStrip)findViewById(R.id.tab_strip);
tab_strp.setTextColor(Color.WHITE);
// tab_strp.setTextSize(14,14);
// tab_strp.setTabIndicatorColor(Color.WHITE);
final MediaPlayer mp = MediaPlayer.create(this, R.raw.firsteps);
mp.start();
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
if(hasFocus){
ImageView welcomeText = (ImageView)findViewById(R.id.btsMainTextImage);
//welcomeText.animate().rotation(1440f).setDuration(2000);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.share) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import java.util.Locale;
//final MediaPlayer mp = MediaPlayer.create(this, R.raw.short_whoosh2);
public ma_pager_adapter(FragmentManager fm) {
super(fm);
}
//final MediaPlayer mp = MediaPlayer.create(this, R.raw.short_whoosh2);
@Override
public Fragment getItem(int i) {
switch (i) {
case 0:
tab1 t1 = new tab1();
return t1;
case 1:
tab2 t2 = new tab2();
return t2;
case 2:
tab4 t4 = new tab4();
return t4;
case 3:
tab3 t3 = new tab3();
return t3;
case 4:
tab5 t5 = new tab5();
return t5;
}
return null;
}
@Override
public int getCount() {
return 5;
}//set the number of tabs
@Override
public CharSequence getPageTitle(int position) {
Locale l = Locale.getDefault();
switch (position) {
case 0:
return "Tab1";
case 1:
return "Tab2";
case 2:
return "Tab3";
case 3:
return "Tab4";
case 4:
return "Tab5";
}
return null;
}
}