2013-12-10 4 views
0

У меня есть макет с TexView и ListView. ListView заполняет всю страницу в эмуляторе. Когда я уменьшаю размеры ListView, он, похоже, не работает. Пожалуйста, обратитесь к этому изображению:Как установить размер контура, например listview, spinner и т. Д.?

enter image description here

Это один справа. Он занимает всю желтую часть. Как я могу изменить свой размер в свойствах?

это .xml,

<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context=".FourthActivity" > 

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

<ListView 
    android:id="@+id/listView1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/lightskyblue" 
    android:entries="@array/Cities" 
    android:overScrollMode="always" 
    android:scrollbarStyle="insideInset" 
    android:transcriptMode="alwaysScroll" 
    android:visibility="visible" > 

</ListView> 

ответ

0

Оберните ваш ListView внутри LinearLayout или RelativeLayout. Установите ширину/высоту ListView в «fill_parent», а затем соответствующим образом измените размер контейнера.

Попробуйте использовать этот 2 колонки макет (изменить ширину, высоту и вес атрибуты внутренних LinearLayouts чтобы удовлетворить ваши потребности):

<?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:paddingBottom="@dimen/activity_vertical_margin" 
      android:paddingLeft="@dimen/activity_horizontal_margin" 
      android:paddingRight="@dimen/activity_horizontal_margin" 
      android:paddingTop="@dimen/activity_vertical_margin" 
      tools:context=".FourthActivity" 
      android:orientation="horizontal" 
      android:weightSum="2" 
      android:baselineAligned="false"> 
     <LinearLayout 
       android:id="@+id/first_column" 
       android:orientation="vertical" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1"> 
      <TextView 
        android:id="@+id/textView1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/hello_world" /> 
     </LinearLayout> 
     <LinearLayout 
       android:id="@+id/second_column" 
       android:orientation="vertical" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1"> 
      <ListView 
        android:id="@+id/listView1" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:background="@color/lightskyblue" 
        android:entries="@array/Cities" 
        android:overScrollMode="always" 
        android:scrollbarStyle="insideInset" 
        android:transcriptMode="alwaysScroll" 
        android:visibility="visible" /> 
     </LinearLayout> 
</LinearLayout> 
+0

Спасибо, независимо от того, как я установил ж/ч, чтобы заполнить или , он отказывается изменять размер контейнера. как будто он любит занимать все пространство. в чем дело? – learner1

+0

вы можете разместить здесь свой xml-код ... –

+0

Я добавляю его. PLS проверить. – learner1

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