1

searchfragmentという名前のこのフラグメントを作成しました。以下に、searchfragmentのレイアウトXMLファイルがあります。残念ながら、デザインは私が望むほど滑らかではありません。

最初の行:ウェルカムテキスト(機能する)2番目の行:検索入力フィールド(これも機能する)Thirt行(ここでは複雑になります):「Searchfor」という名前のテキストがあるはずです。次に、検索できるアイテム(名前、年、価格など)を含むスピナー。次に、[検索]ボタンがあります。次に、出力を並べ替えることができます。したがって、「並べ替え」のテキスト、基準のあるスピナー、並べ替えボタンがあります。最良の場合、検索セクションは左に揃え、並べ替えは右に揃える必要がありますが、それでも中央に配置します。4行目:出力フィールド。要素はすべて私のデバイスに存在するため、Eclipseのグラフィックレイアウトにはありません。私はそれを機能させるために何時間も試みましたが、あなたがあなたのオブジェクトをsseingしていないならそれはちょっと難しいです。

長いテキスト-短いタスク:デザインを最適化するのを手伝ってください。

searchfragment.xml:

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

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_gravity="center"
        android:text="@string/welcome" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <EditText
            android:id="@+id/edit_message"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:hint="@string/edit_message" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center|center_horizontal"
        android:layout_marginTop="8dp" >

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/search_for" />

        <Spinner
            android:id="@+id/criterion"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:entries="@array/searcharray"
            android:prompt="@string/prompt" />

        <Button
            android:id="@+id/btnSubmit"
            android:layout_width="136dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:background="@drawable/android"
            android:onClick="sendMessage"
            android:text="@string/button_send" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/sort_for"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <Spinner
                android:id="@+id/sort"
                android:layout_width="wrap_content"
                android:layout_height="0dip"
                android:layout_weight="1"
                android:entries="@array/sortarray"
                android:prompt="@string/prompt" />

        </LinearLayout>

        <Button
            android:id="@+id/sort_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:background="@drawable/android"
            android:onClick="sortAgain"
            android:text="@string/button_send" />

    </LinearLayout>

<ScrollView
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
     <TextView
        android:id="@+id/showResults"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium" />
</ScrollView>


</LinearLayout>

現在のデザインの写真を追加しました。赤い枠で囲まれたスペースは3番目の「行」であり、変更する必要があります。2番目のスピナーは(理由はわかりませんが)幅が広すぎます。それは最初のものと同じくらい広いはずです。次に、すべての要素がほぼ同じ高さになり、要素が中央に配置される必要があります。

現在の状態

4

1 に答える 1

1

あなたはレイアウトで正しい軌道に乗っていますが、2番目が非常に多くのスペースを占めている理由は、それを 1 にSpinner設定したためです。自由。layout_weightlayout_weight

アイテムが画面上の相対的なスペースを占有するようにしたい場合は、そのまま使用してlayout_weight、すべてのアイテムにそのプロパティを与えることができます。

たとえば、3 番目の行については、LinearLayout周囲のを取り除き、いくつかのプロパティをSpinner変更して、すべてのアイテムに を付けます。layout_widthlayout_weight

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center|center_horizontal"
    android:layout_marginTop="8dp" >

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/search_for" />

    <Spinner
        android:id="@+id/criterion"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:entries="@array/searcharray"
        android:prompt="@string/prompt" />

    <Button
        android:id="@+id/btnSubmit"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:background="@drawable/android"
        android:onClick="sendMessage"
        android:text="@string/button_send" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/sort_for"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <Spinner
        android:id="@+id/sort"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:entries="@array/sortarray"
        android:prompt="@string/prompt" />

    <Button
        android:id="@+id/sort_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:background="@drawable/android"
        android:onClick="sortAgain"
        android:text="@string/button_send" />

</LinearLayout>

これにより、すべてのアイテムの重みが等しくTextViewsなるため、 は と同じサイズにSpinnersなり、 は と同じサイズになりButtonsます。アトリビュートをいじって、アトリビュートをより相対的なものにします。たとえば、を の 2 倍のサイズにしlayout_weightたい場合は、アトリビュートを 2に設定します。ButtonsSpinnerslayout_weight

于 2013-02-13T17:56:21.753 に答える