0

以下に正確なレイアウトを掲載しました。フッターの内側に画像とテキストを垂直方向に中央揃えで表示したい。私は適用しました:

 android:gravity="center_vertical|center"

これらの要素を含む LinearLayout と内部の TextView の両方に対して、それでも行全体の画像とテキストがフッターの上部に向かって遠すぎます。垂直方向の中央に配置したいのですが、常にフッターの上位 30% にあります。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<TextView
    android:id="@+id/someMessageMessage"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
     android:visibility="gone"        
     android:layout_margin="10dip"/>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:gravity="center_vertical|center"
    android:paddingBottom="2dip"
    android:paddingTop="16dip" >

    <ImageView
        android:id="@+id/myImg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dip"
        android:paddingTop="3dip"
        android:src="@drawable/picimg" >
    </ImageView>

    <TextView
        android:id="@+id/myMessage"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dip"
        android:layout_marginRight="10dip"
        android:gravity="center_vertical|center"
        android:text="This message appears way to close to the top of the footer. It should be along with the image in the center:"
        android:textStyle="bold"/>
</LinearLayout>

<Button
    android:id="@+id/myButton"
    style="@style/mybuttonstyle"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dip"
    android:text="@string/lbl_send"
    android:visibility="gone" />
 </LinearLayout>
4

2 に答える 2

0

画像の大きさは?問題はあなたの2番目にあると思いますLinearLayout。高さを「wrap_content」に設定しているため、最大の子と同じ大きさになります。画像とテキストがほぼ同じ高さである場合、何かが中央に配置されているようには見えません。高さを十分に大きくすることで、この理論をテストできます。

于 2012-08-29T02:09:23.803 に答える
0

あなたのレイアウトを見た後、TextView に android:paddingTop を与えていないようです。そのため、トップに表示されます。さらに、レイアウトに適している場合は、 ImageView から android:paddingTop を削除することもできます。それが役立つことを願っています。

于 2012-08-29T01:29:14.323 に答える