【发布时间】:2015-05-23 13:40:40
【问题描述】:
我想像下面给出的这个图片链接一样设计 listView,http://i.stack.imgur.com/M8oQY.png,我尝试了所有类型的布局,但仍然无法像这样定义 listview,请帮助我, 我的代码如下。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:background="#ffff"
android:focusable="false"
android:id="@+id/notifTable"
android:layout_height="fill_parent">
<LinearLayout
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:background="#08707D"
android:orientation="vertical"
android:id="@+id/tableRow1">
<ImageView
android:layout_height="60dp"
android:layout_width="60dp"
android:src="@drawable/alert"
android:padding="5dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:background="#08707D"
android:layout_weight="1"
android:orientation="vertical"
android:id="@+id/tableRow2"
>
<TextView
android:id="@+id/label1"
android:layout_height="match_parent"
android:layout_width="fill_parent"
android:text="@string/hello_world"
android:singleLine="true"
android:layout_weight="0.5"
android:textColor="@color/button"
style="@style/listTextStyle"
>
</TextView>
<TextView
android:id="@+id/label2"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="@string/hello_world"
android:singleLine="true"
android:layout_weight="0.5"
android:textColor="@color/button"
>
</TextView>
</LinearLayout>
</LinearLayout>
【问题讨论】:
-
你有这个list_item_view每个的listview
-
我在我的自定义适配器中添加了这个带有列表视图的布局
-
那么你是不是没有得到图片中的列表视图或者你什么都没有得到
-
i.stack.imgur.com/UnVJL.png,我是这样看的
-
问题是您使用的是水平线性布局,并且您已将图像视图的宽度/高度设置为 60dp。然后,您的其他线性布局(用于两个文本)是
adopting这个高度为 60dp 以显示其内容。尝试将 ImageView 的宽度/高度设置为wrap_content,看看这是否会改变事物的显示方式。我还建议使用 RelativeLayout 作为最顶层的布局和 ImageView 的父级而不是线性布局,但这更多是个人喜好和优化技巧。
标签: android android-layout listview android-listview