2016-08-09 82 views
0

我想在我自己的Android應用程序中使用選項卡,但對我來說存在問題。我嘗試在右側進行TabWidget對齊,以便將第一個選項卡標題放置在右側。我在網上找到了一些解決方案,例如將TabWidget引力設置爲Right,在LinearLayout中嵌套TabWidget並將其重力設置爲正確,但它們沒有工作。Android右對齊TabWidget

這是我的代碼:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context="ir.andrun.tabbased.Main" 
    tools:showIn="@layout/app_bar_main"> 

    <TabHost 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/tabHost"> 

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

      <HorizontalScrollView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:scrollbars="none"> 
       <TabWidget 
        android:id="@android:id/tabs" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content"> 

         <TextView 
          android:tag="tab0" 
          android:text="Tab 1" 
          android:layout_width="wrap_content" 
          android:layout_height="fill_parent" /> 
         <TextView 
          android:tag="tab1" 
          android:text="Tab 2" 
          android:layout_width="wrap_content" 
          android:layout_height="fill_parent" /> 
         <TextView 
          android:tag="tab2" 
          android:text="Tab 3" 
          android:layout_width="wrap_content" 
          android:layout_height="fill_parent" /> 

       </TabWidget> 
      </HorizontalScrollView> 
      <FrameLayout 
       android:id="@android:id/tabcontent" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

       <LinearLayout 
        android:id="@+id/linearLayout" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:orientation="vertical"> 

        <TextView 
         android:text="Tab 1" 
         android:layout_width="wrap_content" 
         android:layout_height="fill_parent" /> 

       </LinearLayout> 

       <LinearLayout 
        android:id="@+id/linearLayout2" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:orientation="vertical"> 

        <TextView 
         android:text="Tab 2" 
         android:layout_width="wrap_content" 
         android:layout_height="fill_parent" /> 

       </LinearLayout> 

       <LinearLayout 
        android:id="@+id/linearLayout3" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:orientation="vertical"> 

        <TextView 
         android:text="Tab 3" 
         android:layout_width="wrap_content" 
         android:layout_height="fill_parent" /> 

       </LinearLayout> 
      </FrameLayout> 
     </LinearLayout> 
    </TabHost> 
</RelativeLayout> 

這是結果:

enter image description here

普萊斯有人幫助我。

坦克。

回答

0

選項0:嘗試tabhost設置爲android:gravity="end"

選項1:嘗試tabhost設置爲android:layout_alignRight="true"android:layoutParentEnd="true"

選項2:tabhost

之前添加空間刺輥上
<!-- Take up space --> 
    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="0.1"/> 

希望這些之一是你正在尋找。