2012-02-12 10 views
0

私が代わりにカスタムヘッダーのタイトルバーどのようにアンドロイドテーブルレイアウトのアイコンを右に置くのですか?

、私は以下を示し、と私は2つのアイコンを配置すると、テキストは右揃えが、私はandroid:layout_gravity="right"を使用する場合、動作しないようですXMLのような今私のレイアウトのtablelayout使用どうすればいいのですか?

これは私のレイアウトxmlです:あなたが設定

< ? xml version="1.0" encoding="utf-8"?> 
    < LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" >  
     <TableLayout 
      android:id="@+id/tableLayout1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="right" 
      android:background="#4494D1" > 

      <TableRow 
       android:id="@+id/tableRow1" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="right" > 

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

        <TextView 

         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center_vertical" 
         android:text="简易尺子" 
         android:textColor="#fff" 
         android:textSize="25dp" 
         android:layout_marginTop="5dp" 
         android:layout_marginLeft="15dp" 
         /> 

       </LinearLayout> 

       <LinearLayout 
        android:id="@+id/linearLayout1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:orientation="vertical" 

        > 

        <ImageButton 
         android:id="@+id/imageButton1" 
         android:layout_width="28dp" 
         android:layout_height="28dp" 
         android:background="@drawable/android2" 
         android:layout_marginLeft="15dp" 
         android:layout_marginRight="15dp" 
         android:layout_marginTop="5dp"/> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center" 
         android:text="关于" 
         android:textColor="#fff" /> 

       </LinearLayout> 

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

        <ImageButton 
         android:id="@+id/imageButton2" 
         android:layout_width="28dp" 
         android:layout_height="28dp" 
         android:background="@drawable/programs" 
         android:layout_marginLeft="15dp" 
         android:layout_marginRight="15dp" 
         android:layout_marginTop="5dp" /> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center" 
         android:text="帮助" 
         android:textColor="#fff" /> 

       </LinearLayout> 
      </TableRow> 
     </TableLayout> 

    <SurfaceView 
     android:layout_width="match_parent" 
     android:id="@+id/surfaceView1" 
     android:layout_height="match_parent"> 
    </SurfaceView> 
</LinearLayout> 

答えて

0

レイアウト重力のTableRowでTextViewImageViewの配置に影響を与えることはなく、むしろそれがされていないLinearLayoutラップでそれらを配置しますがかなり必要なもの。

<TableLayout 
    android:layout_width="fill_parent" 
    android:layout_width="wrap_content" 
    android:stretchColumns="0,1"> 

これは、生の最初の2つのカラムが拡張し、これ右側に右端の列を縮小行います:私はあなたのTableLayoutに次の属性を定義示唆しています。

NOTE(重要)現在、あなたは定義されている有効なレイアウトを持っていない:あなたはLinearLayoutTableRowを持っている - これは許可されていません - あなたは、私が定義されているもののようTableLayout内の行を配置する必要があります。

+0

私のために働く、ありがとう! – chanjianyi

0
try this 


<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 


    <TableLayout 
     android:id="@+id/tableLayout1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" > 

     <TableRow 
      android:id="@+id/tableRow3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:padding="5dip" > 

      <TextView 
       android:id="@+id/textView2" 
       android:text="简易尺子" 
       android:textAppearance="?android:attr/textAppearanceLarge" /> 

      <RelativeLayout 
       android:id="@+id/relativeLayout2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:gravity="right" > 

       <ImageButton 
        android:id="@+id/imageButton1" 
        android:layout_width="28dp" 
        android:layout_height="28dp" 
        android:layout_marginRight="10dp" 
        android:layout_toLeftOf="@+id/imageButton2" /> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_below="@+id/imageButton1" 
        android:layout_marginRight="10dp" 
        android:layout_toLeftOf="@+id/text2" 
        android:text="关于" 
        android:textColor="#fff" /> 

       <ImageButton 
        android:id="@+id/imageButton2" 
        android:layout_width="28dp" 
        android:layout_height="28dp" 
        android:layout_alignParentRight="true" /> 

       <TextView 
        android:id="@+id/text2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentRight="true" 
        android:layout_below="@+id/imageButton2" 
        android:text="帮助" 
        android:textColor="#fff" /> 
      </RelativeLayout> 
     </TableRow> 
    </TableLayout> 

    <SurfaceView 
     android:id="@+id/surfaceView1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_below="@+id/tableLayout1" > 
    </SurfaceView> 

</RelativeLayout> 
関連する問題