如何设置像listview,spinner等大纲的大小?

时间:2013-12-10 14:18:59

标签: android android-layout android-listview

我的布局包含TexViewListViewListView填充模拟器中的整个页面。当我减少ListView的尺寸时,它似乎不起作用。请参考此图片:

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>

1 个答案:

答案 0 :(得分:0)

在LinearLayout或RelativeLayout中包装ListView。将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>