0

レイアウト.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <RelativeLayout
        android:id="@+id/viewPost"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_marginTop="14dp"
        android:background="@color/bg_blue"
        android:gravity="center" >

        <ImageView
            android:id="@+id/ic_viewPost"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_view" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_toRightOf="@id/ic_viewPost"
            android:gravity="center"
            android:text="View post"
            android:textColor="@color/white"
            android:textSize="14sp"
            android:textStyle="bold" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/socialShare"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_marginTop="14dp"
        android:background="@color/bg_light_grey"
        android:gravity="center" >

        <ImageView
            android:id="@+id/ic_socialShare"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_share_post" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_toRightOf="@id/ic_socialShare"
            android:gravity="center"
            android:text="Share with others"
            android:textColor="@color/text_dark_grey"
            android:textSize="14sp"
            android:textStyle="bold" />
    </RelativeLayout>
</LinearLayout>

グラフィカルなレイアウト:

ここに画像の説明を入力

実際のデバイスで:

ここに画像の説明を入力

グラフィカルなレイアウトでは思いどおりに見えますが、実際のデバイスではまったく異なります。

最初の相対レイアウトでは、ImageView と TextView はまったく整列していません。

2 番目の相対レイアウトでは、TextView が ImageView の下に配置されているように見えます。

ありがとうございました。

4

3 に答える 3

0

ペアの代わりにこれを使用してくださいImageView-TextView

    <TextView
    android:drawableLeft="@drawable/ic_viewPost"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:text="View post"
    android:textColor="@color/white"
    android:textSize="14sp"
    android:textStyle="bold" />
于 2013-09-11T05:18:20.060 に答える
0

textViews と check. の両方から android:gravity= "center" を削除します。線形レイアウトで重心を既に使用しているため、問題を解決する必要があります。

于 2013-09-11T05:19:07.640 に答える
0

この属性を TextView と ImageView に追加します。

  android:layout_centerVertical="true"
于 2013-09-11T05:21:34.370 に答える