12

次の XML があります。

<RelativeLayout android:id="@+id/cover_box"
    android:layout_width="wrap_content" android:layout_height="wrap_content">
    <ImageView android:id="@+id/cover"
        android:layout_width="wrap_content" android:layout_height="wrap_content" />
    <ImageView android:id="@+id/download" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:src="@drawable/mark_download"
        android:layout_centerInParent="true" android:layout_marginTop="90px" />
</RelativeLayout>

しかし、marginTop が無視されているようです。

4

5 に答える 5

28

2 番目の画像を画面の中央から 90 dp にしたい場合は、パディングを制御して画像を下に移動できる FrameLayout に置き換えることができます。

<FrameLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true"
    android:paddingTop="90dp">
    <ImageView android:id="@+id/download" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:src="@drawable/mark_download"/>
</FrameLayout>
于 2011-10-25T20:30:31.447 に答える
9

親でcenterを使用すると、ビューは直接中央に配置されます。マージントップは、オブジェクトがビューのトップから90ピクセル以内にある場合にのみ機能します。したがって、中央のビューを押し下げて、その上に少なくとも90pxのスペースを確保します。したがって、無視されているわけではありませんが、本来あるべき効果はありません。

于 2011-10-25T20:23:05.760 に答える
3

プログレスバーを下に表示したいandroid:layout_centerInParent="true"ので、ダミーTextViewを追加して centerInParent に設定しました。次に、プログレスバーをその下に置きます。これで、中心からの距離を 2 つの方法で増やすことができます。最初に TextView の marginTop を増やし、次に TextView の高さを増やします。

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

    <FrameLayout
        android:id="@+id/splash_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <TextView
        android:id="@+id/txt1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true" />

    <com.s3.tdd.interfaces.CircularProgressBar
        android:id="@+id/circularprogressbar2"
        style="@style/Widget.ProgressBar.Holo.CircularProgressBar"
        android:layout_width="110dip"
        android:layout_height="110dip"
        android:layout_below="@+id/txt1"
        android:layout_centerHorizontal="true" />

</RelativeLayout>
于 2014-07-17T12:27:12.483 に答える
1

imageview を他の ViewGroup (RelativeLayout レイアウトの LinearLayout) 内に配置し、imageview のマージンを残して、ViewGroup に対して行うandroid:centerInParent="true"ことができます。

<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">

    <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:centerInParent="true">
           <ImageView android:id="@+id/download" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/mark_download" android:layout_marginTop="90px" />    
    </LinearLayout>    
</RelativeLayout>
于 2015-04-21T21:11:54.343 に答える