2014-02-17 3 views
0

이미지에 표시된대로 레이아웃의 특정 위치에 탭 막대를 설정하는 방법 xml 레이아웃의 3 개의 상대적인 뷰와 하나의 세 번째로 설정된 탭 호스트처럼 설정 레이아웃 또한 두 번째 레이아웃이는 ..... 레이아웃의 특정 위치에 탭을 설정하는 방법

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> 

,210

이있다 클래스 파일 ...

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 "