7

と がImageViewありTextViewます。TextView画像ビューの下に配置したいのですが、中央を中央に(水平軸に沿って)TextView揃えます。ImageViewのテキストがTextView大幅に大きくまたは小さく変更された場合、テキストの中央は常に の中央に揃える必要がありますImageView。これは可能xmlですか?

4

3 に答える 3

7

はい、単に両方の要素をLinearLayoutandroid:gravity設定された垂直に含めることを検討していますcenter_horizontal

このようなもの:

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

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ... />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        ... />

</LinearLayout>

TextViewの幅はであるため、wrap_contentその重力を設定する必要はありません。安全のためだけに行います(さらに、幅も設定する場合がありmatch_parentます)。

于 2012-06-25T06:37:54.937 に答える
0

次のように RealtiveLayout を利用できます。

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_horizontal"
    android:orientation="vertical"
    ... >

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ... />

    <TextView
        android:layout_below="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
         />

</RelativeLayout>

テキストビューを1行のみにしたい場合は、次のプロパティをTextViewに追加します

android:ellipsezed="終了" android:singleLine="true"

特定のレイアウトを使用して既存のレイアウトに追加すると、探している結果が得られます..

この説明がうまくいくことを願っています..

于 2012-06-25T06:51:08.330 に答える
0

セットTextView android:layout_width="fill_parent"してセットandroid:gravity="center"TextViewます。

お役に立てると思います。

ありがとう

于 2012-06-25T06:37:06.270 に答える