2011-01-13 4 views
1

alt textAndroid : 탭 상단의 레이아웃

알 수 있듯이 선형 레이아웃이 탭 위에 있습니다. 내가 원했던 것은 LinearLayout 하단을 탭 상단에 정렬하는 것입니다.

또는 RelativeLayout을 탭 상단에 정렬해도됩니다. 탭의 코드 여기

<?xml version="1.0" encoding="UTF-8"?> 
<RelativeLayout android:id="@+id/RelativeLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"> 
    <LinearLayout android:layout_width="fill_parent" android:orientation="vertical" android:layout_height="wrap_content" android:id="@+id/LinearLayout02" android:layout_alignParentBottom="true"> 
     <FrameLayout android:id="@+id/FrameLayout02" android:layout_height="wrap_content" android:layout_width="fill_parent" android:paddingTop="20sp" android:paddingBottom="20sp"> 
      <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/record" android:layout_gravity="center_horizontal" android:id="@+id/RecordImageButton"></ImageButton> 
     </FrameLayout> 
     <SeekBar android:id="@+id/SeekBar01" android:layout_height="wrap_content" android:layout_width="fill_parent" android:paddingBottom="5sp" android:paddingLeft="10sp" android:paddingRight="10sp"></SeekBar> 
     <FrameLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/FrameLayout03"> 
      <LinearLayout android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/LinearLayout02" android:layout_gravity="center_horizontal"> 
       <ImageButton android:layout_width="wrap_content" android:id="@+id/ImageButton01" android:layout_height="wrap_content" android:src="@drawable/play_rev"></ImageButton> 
       <ImageButton android:layout_width="wrap_content" android:id="@+id/ImageButton02" android:layout_height="wrap_content" android:src="@drawable/play_stop"></ImageButton> 
       <ImageButton android:layout_width="wrap_content" android:id="@+id/ImageButton03" android:layout_height="wrap_content" android:src="@drawable/play"></ImageButton> 
      </LinearLayout> 
     </FrameLayout> 
    </LinearLayout> 
</RelativeLayout> 

된다 :

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/tabhost" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 

     <TabWidget 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@android:id/tabs" 
     android:layout_alignParentBottom="true" /> 

     <FrameLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:id="@android:id/tabcontent" /> 

    </RelativeLayout> 
</TabHost> 

MainActivity, 각 탭 활동을 설정

public void initTabs() 
{ 
    Resources res = getResources(); // Resource object to get Drawables 
    TabHost tabHost = getTabHost(); // The activity TabHost 
    TabHost.TabSpec spec; // Resusable TabSpec for each tab 
    Intent intent; // Reusable Intent for each tab 

    intent = new Intent().setClass(this, FirstActivity.class); 
    spec = tabHost.newTabSpec("tab1").setIndicator("Tab", 
         res.getDrawable(R.drawable.ic_tab_artists)) 
        .setContent(intent); 
    tabHost.addTab(spec); 

    intent = new Intent().setClass(this, SecondActivity.class); 
    spec = tabHost.newTabSpec("tab2").setIndicator("Tab 2", 
         res.getDrawable(R.drawable.ic_tab_artists)) 
        .setContent(intent); 
    tabHost.addTab(spec); 

    intent = new Intent().setClass(this, ThridActivity.class); 
    spec = tabHost.newTabSpec("tab3").setIndicator("Tab 3", 
         res.getDrawable(R.drawable.ic_tab_artists)) 
        .setContent(intent); 
    tabHost.addTab(spec); 

    tabHost.setCurrentTab(0); 
} 
여기

상기 뷰에 해당하는 코드의

답변

0
<?xml version="1.0" encoding="UTF-8"?> 
<RelativeLayout android:id="@+id/RelativeLayout01" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
    <LinearLayout android:layout_width="fill_parent" 
     android:orientation="vertical" android:id="@+id/LinearLayout02" 
     android:layout_alignParentBottom="true" android:weightSum="1" 
     android:layout_height="wrap_content"> 
     <LinearLayout android:id="@+id/LinearLayout03" 
      android:layout_width="fill_parent" android:layout_height="fill_parent" 
      android:layout_weight=".25" android:weightSum="1" 
      android:orientation="vertical"> 
      <FrameLayout android:id="@+id/FrameLayout02" 
       android:layout_height="wrap_content" android:layout_width="fill_parent" 
       android:paddingTop="20sp" android:paddingBottom="20sp" 
       android:layout_weight=".5"> 
       <ImageButton android:layout_width="wrap_content" 
        android:layout_height="wrap_content" android:src="@drawable/record" 
        android:layout_gravity="center_horizontal" android:id="@+id/RecordImageButton"></ImageButton> 
      </FrameLayout> 
      <SeekBar android:id="@+id/SeekBar01" android:layout_height="wrap_content" 
       android:layout_width="fill_parent" android:paddingBottom="5sp" 
       android:paddingLeft="10sp" android:paddingRight="10sp"></SeekBar> 
      <FrameLayout android:layout_width="fill_parent" 
       android:layout_height="wrap_content" android:id="@+id/FrameLayout03"> 
       <LinearLayout android:layout_height="wrap_content" 
        android:layout_width="wrap_content" android:id="@+id/LinearLayout02" 
        android:layout_gravity="center_horizontal"> 
        <ImageButton android:layout_width="wrap_content" 
         android:id="@+id/ImageButton01" android:layout_height="wrap_content" 
         android:src="@drawable/play_rev"></ImageButton> 
        <ImageButton android:layout_width="wrap_content" 
         android:id="@+id/ImageButton02" android:layout_height="wrap_content" 
         android:src="@drawable/play_stop"></ImageButton> 
        <ImageButton android:layout_width="wrap_content" 
         android:id="@+id/ImageButton03" android:layout_height="wrap_content" 
         android:src="@drawable/play"></ImageButton> 
       </LinearLayout> 
      </FrameLayout> 
     </LinearLayout> 
     <LinearLayout android:id="@+id/TabLayout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight=".75"> 
     </LinearLayout> 
    </LinearLayout> 
</RelativeLayout> 

TabHost를 TabLayout (마지막 LinearLayout)에 추가합니다. 희망이 당신의 문제를 해결할 것입니다.

+0

아니요, 두 가지 다른보기가 있어야합니다. – Awesome

+0

괜찮습니다. 만약 당신이 단지'addView' 귀하의 Tabhost 것들보기 내 TabLayout (LinearLayout) 코드에서 수 있습니다. – Sen

0

당신은 PARAMS와 규칙을 만들 수 있습니다 :

RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT) 

params.addRule(RelativeLayout.Top, anotherView.getId()); 

이 라인은 하나의보기 바닥 위에 다른된다는 것을 의미합니다 ...이 일을 할 수 있지만,이 XML에 그렇게 adviced된다.