2012-04-09 14 views
1

こんにちは、アイコンの中心をリニアビューのテキストと同じ行にすることができますが、右の矢印の画像を追加して相対的な表示に切り替える必要があります。画像に示されているように、私は相対ビューの左のアイコンを線形のように見えるように設定することはできません。私は右のアイコン滞在を矢印にしたいAndroidの相対レイアウトで画像を中央に置くことはできません

EDIT

enter image description here
左画像は線形で、右は相対的です。

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/layercontainer" 
android:orientation="horizontal" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:padding="10dp"> 
<ImageView android:id="@+id/categoryIcon" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:gravity="center_vertical" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentBottom="true" 
    android:layout_marginRight="15dp" 
    android:layout_marginTop="5dp" 
    android:layout_marginBottom="5dp" /> 
<TextView android:id="@+id/categoryTitle" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:gravity="center_vertical" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentBottom="true" 
    android:layout_toRightOf="@id/categoryIcon" 
    android:textStyle="bold" 
    android:textSize="22dp" 
    android:textColor="#000000" 
    android:layout_marginTop="5dp" 
    android:layout_marginBottom="5dp" /> 
<ImageView 
     android:id="@+id/nextIcon" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center_vertical" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true" 
     android:layout_marginTop="5dp" 
     android:layout_marginBottom="5dp"/> 
</RelativeLayout> 
+0

申し訳ありませんが私は明確な説明をしませんでした。 アライメントが線形レイアウトで同じように見えるように、矢印が同時に右側に残るようにします。 – Eric

答えて

4

私はdrawableLeftとdrawableRight

android:drawableLeft="@drawable/whatever" 
android:drawableRight="@drawable/arrow" 
android:width="fill_parent" 

その方法をのTextViewのプロパティを使用して、センターへのTextViewの重力を設定することをお勧め、すべてがするのではなく、単一のTextViewを使用して、

もOKでなければなりませんRelativeLayout + 3回のビューは、シンプルさの大幅な向上です。とにかく、3つのビューに固執すれば、RelativeLayoutの代わりにLinearLayoutを使うのは良いアドバイスです。

+0

アイコンを右側に貼りたいのですが? – Eric

+0

TextViewのwitdhを "fill_parent"にしてみてください。次に、テキストを左にとどめるには、gravityをleft | center_verticalに設定する必要があります。これがうまくいかない場合は、狂っていないし、linearlayout + TextView(アイコン+テキスト)+ ImageView(矢印)に固執しないでください。属性drawablePaddingがありますが、頭痛を引き起こす可能性があります。 – Maragues

+0

アンドロイド:layout_width = "fill_parent"とアンドロイド:drawableRight = "@ drawable/next" 'が動作します。 ありがとうalag Maragues! – Eric

1

LinearLayoutを使用できないのはなぜですか?

が働くだろう。このように思える:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/layercontainer" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:padding="10dp"> 
    <ImageView android:id="@+id/categoryIcon" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:gravity="center_vertical" 
     android:layout_marginRight="15dp" 
     android:layout_marginTop="5dp" 
     android:layout_marginBottom="5dp" /> 
    <TextView android:id="@+id/categoryTitle" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:gravity="center_vertical" 
     android:textStyle="bold" 
     android:textSize="22dp" 
     android:textColor="#000000" 
     android:layout_marginTop="5dp" 
     android:layout_marginBottom="5dp" /> 
    <ImageView 
     android:id="@+id/nextIcon" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:gravity="center_vertical" 
     android:layout_marginTop="5dp" 
     android:layout_marginBottom="5dp"/> 
</LinearLayout> 
+0

アイコンを右側に貼りたいのですが? – Eric

+0

最後のイメージビューを 'android:layout_width =" 0dp "'に変更し、最初の2つが配置された後の残りのスペースをすべて取るように 'android:layout_weight =" 1 "'を追加してから、 'android:layout_gravity =" right ""、これはウィジェットがビュー空間の右側にアライメントされるようにします。それはあなたにあなたが望む外観を与えるはずです。 – Barak

0

あなたべきThe LinearLayout is the most simple layout available in Android. A LinearLayout organizes layout components in a linear fashion horizontally or vertically

Creating Efficient LayoutsはRelativeLayoutとのLinearLayoutのパフォーマンスについて語る

ので、簡単なXML構造のためのユーザーのLinearLayout:私は

関連する問題