2012-04-19 8 views
11

ListViewの行にはRelativeLayoutがあります。行がアンドロイド上のxmlの相対レイアウトで、余白またはパディングが機能しない

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/relativeLayout1" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent"> 

    <ImageView 
     android:id="@+id/placeDetailIcon_Img" 
     android:layout_height="50dp" 
     android:layout_width="50dp" 
     android:layout_alignParentLeft="true" 
     android:paddingBottom="20dp" 
     android:paddingTop="20dp" 
     android:paddingLeft="20dp" 
     android:paddingRight="20dp"/> 
</RelativeLayout> 

、のように見える私にも余裕を持って、それを試してみました:

<ImageView 
    android:layout_height="50dp" 
    android:layout_width="50dp" 
    android:id="@+id/placeDetailIcon_Img" 
    android:layout_alignParentLeft="true" 
    android:layout_marginRight="10dp" 
    android:layout_marginTop="10dp" 
    android:layout_marginLeft="10dp" 
    android:layout_marginBottom="10dp"> 

どちらImageView周りのマージンやパディングを適用します。どのようにこのタイプの間隔を作成するのですか?

私はあなたがのLinearLayoutを使用することをお勧め...それとも属性を削除しようとすることができます
+0

RelativeLayout 'android:layout_height =" wrap_content "'? – zapl

+0

また、リストアイテムが1つのビューだけで表される場合は、 'RelativeLayout'も取り除きます。 –

答えて

5

することができますこの仕事を私と一緒に使ってください:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/relativeLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginLeft="15dp" 
     android:layout_marginTop="15dp" /> 

</RelativeLayout> 

これは役に立ちます。

http://developer.android.com/reference/android/widget/RelativeLayout.html

「あなたはRelativeLayoutの大きさとその子の位置との間の循環依存を持つことができないことに注意してください:ドキュメントから - これに対する解決策を探している誰のために

+0

アンドロイド:layout_marginTopとアンドロイド:paddingTopはどうしてですか? – user2512888

0

android:layout_alignParentLeft="true"

あなたが使用することができますRelativeLayoutでビューを中央にしたい場合:

android:layout_centerHorizontal="true" 
android:layout_centerVertical="true" 
+2

アンドロイド:layout_centerInParent = "true"は、どちらも同じです。 – vm204

2

たとえば、高さがWRAP_CONTENTに設定され、子がALIGN_PARENT_BOTTOMに設定されているRelativeLayoutを設定することはできません。

スクロールビューの内部にrelativeViewを配置すると、いくつかの奇妙な動作があるようです。

私の場合、relativeLayoutをwrap_contentに設定してから、marginBottomをImageViewにALIGN_PARENT_BOTTOM属性で追加しようとしました。明示的に高さを設定すると、最終的には機能しました。

関連する問題