3つのテキストビューを横に並べてレイアウトを作成しようとしています。テキストビューの長さは異なります。同じ幅のテキストビューを行に作成する
私がしたいのは、テキストの長さにかかわらず常にlayout_widthが同じになるように並べ替えることです。私が試した
アプローチ:
1)私はlinear_layoutを使用してtextviewsの重みを設定することが1であることを試みたが、すべてのtextViewsが配置された後、それは残りの幅のためにのみ適用されますので、それはそれをしません。
2)また、テーブルレイアウトを使用し、stretchColumns = "*"を使用してすべての列をストレッチしてみました。しかし、それはまたテキストの長さに必要な幅を割り当て、それだけで列を伸ばします。
3)これはハックですが、これも機能しません。私は3つのテキストビューを持つ相対的なレイアウトの中に線形レイアウトを持たせようとしましたが、テキストを持たずにウエイトを設定することで同じ幅になるようにしました。これはうまくいきますが、リニアレイアウト内のビューの右端と左端にアライメントするために相対レイアウト内にある次のビューが必要です。しかし、これは機能しません。ここに私が使ったレイアウトがあります。
<RelativeLayout
android:layout_width="fill_parent" android:layout_height="fill_parent" >
<!-- This is a hack to have all three textviews in a row to obtain equal width -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView android:id="@+id/tv_ref1"
android:layout_width="0dp" android:layout_height="wrap_content"
android:text="My"
android:layout_weight="1.0"
android:gravity="center" />
<TextView android:id="@+id/tv_ref2"
android:layout_width="0dp" android:layout_height="wrap_content"
android:text="My"
android:layout_weight="1.0"
android:gravity="center" />
<TextView android:id="@+id/tv_ref3"
android:layout_width="0dp" android:layout_height="wrap_content"
android:text="My ghghhfghjjghjkkhgfhfghfjhjh"
android:layout_weight="1.0"
android:gravity="center" />
</LinearLayout>
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/tv_ref1"
android:gravity="center"
android:text="Text Text Text"
android:textColor="@color/white" />
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/tv_ref1"
android:gravity="center_horizontal"
android:text="Med"
android:textColor="@color/white" />
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/tv_ref1"
android:gravity="center"
android:text="Long Text wtwy yu hjsyi"
android:textColor="@color/white" />
</RelativeLayout>
私は何が間違っているのか、どのように行のテキストビューを同じ幅にすることができるのか教えてください。
ありがとうございます。
それは動作しません。私はそれを試してみました。それは他のテキストよりも長いテキストに幅を与えます。 – achie
layout_widthが "wrap_content"の場合、yes;それが "fill_parent"であれば - いいえ。それを試してください –
ああ私の悪い。はい、それは動作します。そして、私のレイアウトコード内のrelativelayout内のlinearlayoutのテキストビューでさえトリックを行います。したがって、すべてのtextviewに対してfill_parentまたは0dpのいずれかでも動作します。また、すべてのtextviewの幅を同じに設定すると効果的です。ありがとうございました。 – achie