2014-02-17 55 views
0

如何设置在布局的特定位置标签栏的特定位置标签如图图像.... 在XML布局我设置像三个相对视图一个又一个选项卡的主机I放于第三布局也有第二个布局是考虑到,但只有标签的布局问题,正确的位置.....如何设置在布局

enter image description here

现在这是xml文件.....

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:weightSum="10" > 

    <RelativeLayout 
     android:id="@+id/rl1" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="3" 
     android:background="@drawable/userprofile_bg" > 

     <ImageView 
      android:id="@+id/imageView1" 
      android:layout_width="100dp" 
      android:layout_height="100dp" 
      android:layout_marginLeft="10dp" 
      android:layout_marginTop="20dp" 
      android:src="@drawable/novak_djokovic_medium" /> 

     <TextView 
      android:id="@+id/se_1_name" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentTop="true" 
      android:layout_marginRight="10dp" 
      android:layout_marginTop="10dp" 
      android:text="NAME" /> 

     <TextView 
      android:id="@+id/se_1_sex" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_below="@id/se_1_name" 
      android:layout_marginRight="10dp" 
      android:layout_marginTop="10dp" 
      android:text=",MALE" /> 

     <TextView 
      android:id="@+id/se_1_age" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/se_1_name" 
      android:layout_marginTop="10dp" 
      android:layout_toLeftOf="@id/se_1_sex" 
      android:text="18" /> 

     <TextView 
      android:id="@+id/se_1_country" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_below="@id/se_1_sex" 
      android:layout_marginRight="10dp" 
      android:layout_marginTop="10dp" 
      android:text="UK" /> 

     <TextView 
      android:id="@+id/se_1_city" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/se_1_sex" 
      android:layout_marginTop="10dp" 
      android:layout_toLeftOf="@id/se_1_country" 
      android:paddingRight="5dp" 
      android:text="LONDON" /> 

     <ImageView 
      android:id="@+id/se_1_bgphoto" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentRight="true" 
      android:layout_marginBottom="10dp" 
      android:layout_marginRight="10dp" 
      android:background="@drawable/bgphoto32x32" /> 

     <ImageView 
      android:id="@+id/se_1_userphoto" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_marginBottom="10dp" 
      android:layout_marginRight="10dp" 
      android:layout_toLeftOf="@id/se_1_bgphoto" 
      android:background="@drawable/userphoto32x32" /> 

     <ImageView 
      android:id="@+id/se_1_edit" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_marginBottom="10dp" 
      android:layout_marginRight="10dp" 
      android:layout_toLeftOf="@id/se_1_userphoto" 
      android:background="@drawable/edit32x32" /> 
    </RelativeLayout> 

    <RelativeLayout 
     android:id="@+id/rl2" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="2" > 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="horizontal" 
      android:weightSum="12" > 

      <RelativeLayout 
       android:id="@+id/rl11" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="3" > 

       <TextView 
        android:id="@+id/we" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerHorizontal="true" 
        android:layout_centerInParent="true" 
        android:layout_centerVertical="true" 
        android:text="123" /> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_below="@id/we" 
        android:layout_centerHorizontal="true" 
        android:layout_centerInParent="true" 
        android:layout_centerVertical="true" 
        android:text="123" /> 
      </RelativeLayout> 

      <RelativeLayout 
       android:id="@+id/rl11" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="3" > 

       <TextView 
        android:id="@+id/we" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerHorizontal="true" 
        android:layout_centerInParent="true" 
        android:layout_centerVertical="true" 
        android:text="123" /> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_below="@id/we" 
        android:layout_centerHorizontal="true" 
        android:layout_centerInParent="true" 
        android:layout_centerVertical="true" 
        android:text="123" /> 
      </RelativeLayout> 

      <RelativeLayout 
       android:id="@+id/rl11" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="3" > 

       <TextView 
        android:id="@+id/we" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerHorizontal="true" 
        android:layout_centerInParent="true" 
        android:layout_centerVertical="true" 
        android:text="123" /> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_below="@id/we" 
        android:layout_centerHorizontal="true" 
        android:layout_centerInParent="true" 
        android:layout_centerVertical="true" 
        android:text="12323" /> 
      </RelativeLayout> 

      <RelativeLayout 
       android:id="@+id/rl11" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="3" > 

       <TextView 
        android:id="@+id/we" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerHorizontal="true" 
        android:layout_centerInParent="true" 
        android:layout_centerVertical="true" 
        android:text="123" /> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_below="@id/we" 
        android:layout_centerHorizontal="true" 
        android:layout_centerInParent="true" 
        android:layout_centerVertical="true" 
        android:text="123" /> 
      </RelativeLayout> 

      <RelativeLayout 
       android:id="@+id/rl112" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="3" > 
      </RelativeLayout> 

      <RelativeLayout 
       android:id="@+id/rl113" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="3" > 
      </RelativeLayout> 

      <RelativeLayout 
       android:id="@+id/rl114" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="3" > 
      </RelativeLayout> 
     </LinearLayout> 
    </RelativeLayout> 

    <RelativeLayout 
     android:id="@+id/rl3" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="5" > 

     <android.support.v4.view.ViewPager 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/s_pager" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" > 
     </android.support.v4.view.ViewPager> 
    </RelativeLayout> 
</LinearLayout> 

这是类文件...

public class settings extends FragmentActivity implements ActionBar.TabListener { 
private ViewPager viewPager; 
private TabsPagerAdapter mAdapter; 
private ActionBar actionBar; 
// Tab titles 
private String[] tabs = { "Top Rated", "Games", "Movies" }; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.settings1); 

    // Initilization 
    viewPager = (ViewPager) findViewById(R.id.s_pager); 
    actionBar = getActionBar(); 
    mAdapter = new TabsPagerAdapter(getSupportFragmentManager()); 

    viewPager.setAdapter(mAdapter); 
    actionBar.setHomeButtonEnabled(false); 
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); 

    // Adding Tabs 
    for (String tab_name : tabs) { 
     actionBar.addTab(actionBar.newTab().setText(tab_name) 
       .setTabListener(this)); 
    } 

    /** 
    * on swiping the viewpager make respective tab selected 
    * */ 
    viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { 

     @Override 
     public void onPageSelected(int position) { 
      // on changing the page 
      // make respected tab selected 
      actionBar.setSelectedNavigationItem(position); 
     } 

     @Override 
     public void onPageScrolled(int arg0, float arg1, int arg2) { 
     } 

     @Override 
     public void onPageScrollStateChanged(int arg0) { 
     } 
    }); 
} 

@Override 
public void onTabReselected(Tab arg0, FragmentTransaction arg1) { 
    // TODO Auto-generated method stub 

} 

@Override 
public void onTabSelected(Tab arg0, FragmentTransaction arg1) { 
    // TODO Auto-generated method stub 

} 

@Override 
public void onTabUnselected(Tab arg0, FragmentTransaction arg1) { 
    // TODO Auto-generated method stub 

} 

}

回答

0

你需要这个视图位置的父视图

<RelativeLayout 
    android:id="@+id/rl3" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="5" > 

    <android.support.v4.view.ViewPager 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/s_pager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 
    </android.support.v4.view.ViewPager> 
</RelativeLayout> 

你可以做定义父相对布局将占据内半屏,比你可以对齐上述布局​​的layout_below="@+id/define your above id here "