2013-11-24 16 views
6

トップバーと画像を含む画面を作りたいと思います。私はトップバーのTextViewとイメージのImageViewを使用します。私は画像ビューにのみパディングを設定したい。私のXMLは以下の通りです。パディングアクションが機能していません。なぜ誰が何をすべきか説明できますか?ImageViewの埋め込みが機能していません

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/background" > 

    <TextView android:id="@+id/topBar" 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:text="@string/home" 
     android:textSize="20sp" 
     android:textColor="#ffffff" 
     android:textStyle="bold" 
     android:shadowColor="#000000" 
     android:shadowRadius="1" 
     android:shadowDy="-1" 
     android:gravity="center" 
     android:background="@drawable/navBar"/> 

    <ImageView android:id="@+id/image" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingLeft="10dp" 
     android:paddingTop="10dp" 
     android:paddingRight="10dp" 
     android:paddingBottom="10dp" 
     android:layout_below="@+id/topBar"   
     android:background="@drawable/image"/> 

</RelativeLayout> 

答えて

9

あなたはそれには、以下の通りであるべきlayout_marginの代わりpaddingを使用する必要があります。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@drawable/background" > 

<TextView android:id="@+id/topBar" 
    android:layout_width="match_parent" 
    android:layout_height="50dp" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:text="@string/home" 
    android:textSize="20sp" 
    android:textColor="#ffffff" 
    android:textStyle="bold" 
    android:shadowColor="#000000" 
    android:shadowRadius="1" 
    android:shadowDy="-1" 
    android:gravity="center" 
    android:background="@drawable/navBar"/> 

<ImageView android:id="@+id/image" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="10dp" 
    android:layout_marginTop="10dp" 
    android:layout_marginRight="10dp" 
    android:layout_marginBottom="10dp" 
    android:layout_below="@+id/topBar"   
    android:background="@drawable/image"/> 

とあなたの代わりに

android:layout_marginLeft="10dp" 
android:layout_marginTop="10dp" 
android:layout_marginRight="10dp" 
android:layout_marginBottom="10dp" 
を使用するので、すべての方向に対して1 layout_marginを指定することができます

ご利用いただけます:

android:layout_margin="10dip" 

希望これはあなたが探しているものです。

<ImageView 
... 
    android:cropToPadding="true" 
    android:padding="15dp" 
    android:scaleType="centerInside" 
... 
+0

はい、これは私が探しているものです。迅速な対応のために@Coderjiに感謝します。 :) – CrazyLearner

+0

これは私の喜びです:)あなたがこの有用なことを発見した場合、あなたはそれが正しいように人々がそれを将来参照することができます:) – Coderji

+1

私は右にそれをチェックして、申し訳ありませんが私の評判のスコア15.以下です。 – CrazyLearner

5

は、このための唯一の解決策は、別の容器にImageViewのを追加している:あなたもcropToPaddingを設定することができます

更新)、そうでない場合は、私にフィードバックを与えます。背景タグがないのに対し、ImageViewの利用代わり

android:background="@drawable/image" 

SRCタグの

android:src="@drawable/image" 

<FrameLayout 
     android:layout_width="40dp" 
     android:layout_height="40dp" 
     android:layout_gravity="center" 
     android:layout_marginRight="10dp" 
     android:padding="10dp" > 

     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_gravity="center" 
      android:background="@drawable/ic_delete_blue" /> 
    </FrameLayout> 
3

はパディングを称えます。 場合によっては、クリック可能なアイコンでは、パディングがビューに属し、クリック領域を大きくするので、パディングの代わりにlayout_marginを使用することは悪い考えです。

関連する問題