0

簡単な質問がありますが、これは私の開発をひどくしています。

さまざまな活動で、私はさまざまな見解を持っています。たとえば、textview、buttonview、editview。私が欲しいのは、すべてのビューが画面に動的に収まる必要があります(1つのビューまたは5つのビューがあるかどうかに関係なく)が、それは起こりません。ビューが画面の外に出る場合もあれば、画面に空白が残る場合もあります。

以下は私が試したものです、私はandroid:layout_height="75dp"を提供したくありません。

F1してください

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >


        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <Spinner
                android:id="@+id/spinner1"
                android:layout_width="fill_parent"
                android:layout_height="75dp"
                android:background="@drawable/btnmusic"
                android:scaleType="fitCenter" />
        </LinearLayout>

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

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

            <ImageButton
                android:id="@+id/btnplay"
                android:layout_width="wrap_content"
                android:layout_height="75dp"
                android:layout_weight="1"
                android:onClick="onClick"
                android:scaleType="fitXY"
                android:src="@drawable/btnselectedsong" />

            <ImageButton
                android:id="@+id/btnpause"
                android:layout_width="wrap_content"
                android:layout_height="75dp"
                android:layout_weight="1"
                android:src="@drawable/btnplay"
                android:onClick="onClick"
                android:scaleType="fitXY" />
        </LinearLayout>

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

            <ImageButton
                android:id="@+id/btnplay"
                android:layout_width="wrap_content"
                android:layout_height="75dp"
                android:layout_weight="1"
                android:background="@drawable/btnpause"
                android:onClick="onClick"
                android:scaleType="centerInside" />

            <ImageButton
                android:id="@+id/btnpause"
                android:layout_width="wrap_content"
                android:layout_height="75dp"
                android:layout_weight="1"
                android:background="@drawable/btnstop"
                android:onClick="onClick"
                android:scaleType="fitCenter" />
        </LinearLayout>

            <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Medium Text"
            android:textAppearance="?android:attr/textAppearanceMedium" />
    </LinearLayout>
4

4 に答える 4

0
  1. LinearLayout親として持つ
  2. を設定しlayout_height="fill_parent"orientation="horizontal"
  3. viewsあなたが持っているをこの親に追加します
  4. 最後に、すべてのビュー セットにlayout_weight="1"

最後の行では、ビューの数に関係なく、それらはすべて同じ高さでなければならず、最初の行では、すべて一緒にビューが画面全体を占める必要があります。

于 2013-03-08T10:11:06.930 に答える
0

LinearLayout を使用しているので、スペース全体を調整する layout_weight を使用できます。

等間隔とは別に特定のスペースを与えたい場合は、android:weightSum="100" を定義し、要件に応じて子レイアウトに配布できます

いくつかのデモを試して、レイアウトを変更しただけです。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:android:weightSum="100" >


        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="10" >

            <Spinner
                android:id="@+id/spinner1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/btnmusic"
                android:scaleType="fitCenter" />


        </LinearLayout>

       <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="10" >

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

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:orientation="horizontal"
            android:layout_weight="40" >

            <ImageButton
                android:id="@+id/btnplay"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:onClick="onClick"
                android:scaleType="fitXY"
                android:src="@drawable/btnselectedsong" />

            <ImageButton
                android:id="@+id/btnpause"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:src="@drawable/btnplay"
                android:onClick="onClick"
                android:scaleType="fitXY" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:orientation="horizontal"
            android:layout_weight="30" >

            <ImageButton
                android:id="@+id/btnplay"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@drawable/btnpause"
                android:onClick="onClick"
                android:scaleType="centerInside" />

            <ImageButton
                android:id="@+id/btnpause"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@drawable/btnstop"
                android:onClick="onClick"
                android:scaleType="fitCenter" />
        </LinearLayout>
 <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="0dp"
             android:layout_weight="10" >
            <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Medium Text"
            android:textAppearance="?android:attr/textAppearanceMedium" />
       </LinearLayout>
    </LinearLayout>

これがあなたを助けることを願っています。

于 2013-03-08T09:51:58.007 に答える
0

layout_weight=1使用可能なスペースを均等に共有したいすべてのビューに設定します。

あなたのコードのために:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >


        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="odp"
            android:layout_weight="1" >

            <Spinner
                android:id="@+id/spinner1"
                android:layout_width="fill_parent"
                android:layout_height="75dp"
                android:background="@drawable/btnmusic"
                android:scaleType="fitCenter" />
        </LinearLayout>

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

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="odp"
            android:layout_weight="1"
            android:orientation="horizontal" >

            <ImageButton
                android:id="@+id/btnplay"
                android:layout_width="wrap_content"
                android:layout_height="75dp"
                android:layout_weight="1"
                android:onClick="onClick"
                android:scaleType="fitXY"
                android:src="@drawable/btnselectedsong" />

            <ImageButton
                android:id="@+id/btnpause"
                android:layout_width="wrap_content"
                android:layout_height="75dp"
                android:layout_weight="1"
                android:src="@drawable/btnplay"
                android:onClick="onClick"
                android:scaleType="fitXY" />
        </LinearLayout>

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

            <ImageButton
                android:id="@+id/btnplay"
                android:layout_width="wrap_content"
                android:layout_height="75dp"
                android:layout_weight="1"
                android:background="@drawable/btnpause"
                android:onClick="onClick"
                android:scaleType="centerInside" />

            <ImageButton
                android:id="@+id/btnpause"
                android:layout_width="wrap_content"
                android:layout_height="75dp"
                android:layout_weight="1"
                android:background="@drawable/btnstop"
                android:onClick="onClick"
                android:scaleType="fitCenter" />
        </LinearLayout>

            <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="odp"
            android:layout_weight="1"            
            android:text="Medium Text"
            android:textAppearance="?android:attr/textAppearanceMedium" />
    </LinearLayout>
于 2013-03-08T09:41:51.570 に答える
0

相対レイアウトを使用すると、画面の端と水平および垂直の中心に関して機能を定義して、ボタンを動的に配置できます。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >


    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <Spinner
            android:id="@+id/spinner1"
            android:layout_width="fill_parent"
            android:layout_centerHorizontal="true"
            android:background="@drawable/btnmusic"
            android:scaleType="fitCenter" />
    </RelativeLayout>
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/spinner1"
        android:text="Medium Text"
        android:textAppearance="?android:attr/textAppearanceMedium" />
....
....
....
</RelativeLayout>

そのようなものは、動的なレイアウトを提供するはずです。

于 2013-03-08T09:42:59.927 に答える