无法查看列表视图

时间:2016-11-08 06:38:33

标签: android android-layout listview android-arrayadapter

我试图通过数组适配器绑定我的listview。我在列表中有我的列表视图

activity_menu.xml

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

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TableRow>
        <ImageView android:layout_height="wrap_content"
            android:layout_width = "wrap_content"
            android:src="@drawable/saltnpepper"
            android:layout_weight="1"
            android:scaleType="centerInside"/>
    </TableRow>

    <TableRow android:paddingTop="@android:dimen/app_icon_size"><TextView></TextView></TableRow>
<TableRow>
    <ListView android:id="@+id/list1"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_margin="10dp">

    </ListView>
</TableRow>
</TableLayout>

然后我有另一个TextView的布局加载到listView

menulist.xml

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

<TextView 
    android:id="@+id/nameText"
    android:text="@string/app_name"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:textSize="16sp"
    android:textStyle="bold"/>

在我的代码中,我正在执行以下操作,但我的列表视图从未加载过一次

    ArrayList<String> alTest = new ArrayList<String>();
alTest.add("One");
alTest.add("Two");

ArrayAdapter<String> catAdapter = new ArrayAdapter<String>(this, R.layout.menulist, R.id.nameText, alTest);
ListView list = (ListView)findViewById(R.id.list1);
list.setAdapter(catAdapter);

我也尝试过简单的数组而不是arraylist alTest,但没有工作

1 个答案:

答案 0 :(得分:0)

所以问题不在于listview没有加载但是之前的imageview覆盖了更多的屏幕!现在我还有另一个问题(在新帖子上发帖)

<TableRow android:layout_weight="1" android:gravity="center">
        <ImageView android:layout_height="200dp"
            android:layout_width = "match_parent"
            android:src="@drawable/saltnpepper"                
            android:scaleType="centerInside" />
    </TableRow>

图像不会扩展整个屏幕宽度

相关问题