0

に問題がありますRelativeLayout

私は6つViewsを並べて配置しましたが、うまくいきました。

私が抱えている問題はEditTexts. 幅をwrap_contentに設定すると、小さすぎます。

それらをに設定すると、隣のエッジに合わせて調整するのではなくmatch_parent、幅全体を使用します(他のものをオーバーレイしています)。ViewsViews

だから私の質問は、それらに静的な幅を与えずにどのようにフィットさせることができるでしょうか?

これが私のコードです:

<RelativeLayout
    android:id="@+id/relativelayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/tv1"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:text="text 1" />

    <EditText
        android:id="@+id/et1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/tv1"
        android:singleLine="true" />

    <TextView
        android:id="@+id/tv2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/et1"
        android:text="text 2" />

    <EditText
        android:id="@+id/et2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/tv2"
        android:singleLine="true" />

    <TextView
        android:id="@+id/tv3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/et2"
        android:text="text 3" />

    <Spinner
        android:id="@+id/spinner1"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_toRightOf="@+id/tv3" />

</RelativeLayout>
4

2 に答える 2

4

次のコードを試してください。

ボックスのサイズを少し変えたい場合は、静的なサイズを適用するか、ウェイトを少し試して、必要なスペースを確保する必要があります。

ただし、実際にはレイアウトを少し変更することをお勧めします。それらをすべて同じ行に配置するのはやや厄介なようです。これがランドスケープモードの場合を除きます。その後、それは大丈夫かもしれません。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativelayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/tv1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="text 1" />

    <EditText
        android:id="@+id/et1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:singleLine="true" />

    <TextView
        android:id="@+id/tv2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="text 2" />

    <EditText
        android:id="@+id/et2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:singleLine="true" />

    <TextView
        android:id="@+id/tv3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="text 3" />

    <Spinner
        android:id="@+id/spinner1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_toRightOf="@+id/tv3" />

</LinearLayout>

結果のレイアウトの画像:

ここに画像の説明を入力してください

于 2012-07-16T17:11:42.387 に答える
1

相対レイアウトでは、満足のいくラップコンテンツまたは静的な寸法が必要です。私がよく理解していれば、画面の幅の残りを編集テキストで埋める必要があります。LinearLayout とandroid:layout_weightプロパティを使用する必要があります -ここで例を見つけることができます:

<LinearLayout
        android:id="@+id/ll"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation:"horizontal">
        <TextView
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:text="text 1" />

        <EditText
        android:id="@+id/et1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:singleLine="true"/>

        <EditText
        android:id="@+id/et2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:singleLine="true" />

        <TextView
        android:id="@+id/tv3"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:text="text 3" />

        <Spinner
        android:id="@+id/spinner1"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true" />

</LinearLayout>
于 2012-07-16T17:22:47.070 に答える