2013-03-08 2 views
0

У меня есть простой вопрос, но это делает мое развитие ужасным.как заполнить полный экран с различными видами в android

В разных видах деятельности у меня есть другой набор видов. например textview, buttonview, editview. то, что я хочу, все представления должны быть динамически размещены на экране (независимо от того, у меня есть один вид или 5 просмотров), но его не происходит. некоторые временные просмотры выходят на экран, а некоторые пробелы остаются на экране.

bellow - это то, что я пробовал, я не хочу предоставлять андроид: 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> 
+0

использовать «RelativeLayout» в качестве базы. – SudoRahul

ответ

0

установить layout_weight=1 всем WIEWS, которые вы хотите поделиться доступное пространство поровну.

для вашего кода:

<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> 
+0

Шайлендра, когда я применяю картинку в качестве фона, не работает, другой мудрый это работает .. но у меня должно быть изображение в качестве фона на кнопке и все виды – abidkhan303

0

Если вы используете относительный макет можно определить особенности в отношении к краям экрана и горизонтальным и вертикальным обрабатывающим центрам, позволяющим динамической placment кнопок.

<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> 

Нечто подобное должно дать вам динамический макет.

+0

chefburns вы можете ответить на свой ответ с вами, например, – abidkhan303

+0

отредактированный, чтобы включить код для вас , – chefburns

0

Поскольку вы используете LinearLayout, чтобы вы могли использовать layout_weight, который позаботится о настройке всего пространства.

Если вы хотите, чтобы дать конкретное пространство, кроме равноотстояния вы можете определить андроида: 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> 

Надеюсь, это вам поможет.

+0

Ваше решение работает только в том случае, если я не применяю изображение в качестве фона. но линейная компоновка растягивается по размеру изображения. :( – abidkhan303

0
  1. ли LinearLayout, как Родитель
  2. Установите его layout_height="fill_parent" и orientation="horizontal"
  3. Добавьте views у вас есть, к этому родителю
  4. Наконец, чтобы каждый вид набора layout_weight="1"

К последней строке вы имеете в виду, независимо от того, h ow, многие из вас видят, все они должны быть одинаковой высоты, а на 1-й строке вы имеете в виду, все вместе взгляды должны занимать весь экран.

Смежные вопросы