私は次のようにUIを設計しています。ビュー1は画像ですが、異なる画像を表示するとそのサイズは異なります。ビュー2とビュー3のサイズはビュー1によって異なります。これを実現するためにxmlファイルを定義する方法は?ビューのサイズを別のビューのサイズに合わせるにはどうすればよいですか?
ps:デザインはクライアントからのものだから、私はそれを変更できません。
私は次のようにUIを設計しています。ビュー1は画像ですが、異なる画像を表示するとそのサイズは異なります。ビュー2とビュー3のサイズはビュー1によって異なります。これを実現するためにxmlファイルを定義する方法は?ビューのサイズを別のビューのサイズに合わせるにはどうすればよいですか?
ps:デザインはクライアントからのものだから、私はそれを変更できません。
活用のRelativeLayout ....このタスクを達成するために適切な変更を行い、
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_below="@id/view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_toRightof="@id/view1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"/>
</RelativeLayout>
をそれを使用する私は、適切なサイズを設定する最も簡単な方法であるためのLinearLayoutは、ここに優れていると思いますlayout_weightを使用する。 LinearLayout内の1つの要素に対してのみゼロ以外のウェイトを設定すると、残っているすべての領域が使用されます。 layout_weightは、残りのスペースを与えられた重みの比率で除算します。指定されたlayout_width-s(またはheight)を最初に設定した後、残りのスペースのサイズを計算し、次にこれらのサイズをオーバーライドします。いくつかの初期設定の後に残りのスペースではなく固定された比率に画面全体を分割したい場合は、最初に要素のサイズを0に設定する必要があります。次に、View1のサイズをwrap_contentに設定し、適切な方向を0(他の方向に親を埋める)にし、layout_weight = 1を使用します。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical" android:layout_width ="wrap_content"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src=.../>
<SomeKindOfView
android:id="@+id/view2"
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_weight="1"/>
</LinearLayout>
<AnotherView
android:id="@+id/view3"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="1"/>
</LinearLayout>