看不到列表视图
Cant see the 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 但没有成功
所以问题不是 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>
图像没有展开整个屏幕宽度
我正在尝试通过数组适配器绑定我的列表视图。我在布局中有我的列表视图
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 但没有成功
所以问题不是 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>
图像没有展开整个屏幕宽度