我希望listView的item横向显示三块内容,分别位于listitem的左,中,右位置;中间的有两个TextView,竖直排列;下面是代码,调试了一天也没弄出来,麻烦大家帮忙看看,谢谢
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/word"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:text="aaaaaaaaa" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:id="@+id/_en"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="**********" />
<TextView
android:id="@+id/_am"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="+++++++++" />
</LinearLayout>
<TextView
android:id="@+id/meaning"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:layout_gravity="right"
android:text="ddddddddddd" />
</LinearLayout>
PHP中文网2017-04-18 09:15:15
Linear layout, your first textview has been set to occupy the entire space. Of course, your middle and right layouts cannot be released. Let’s assume that the horizontal space is evenly distributed among the left, middle and right parts. You can write it like this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="center_vertical">
<TextView
android:id="@+id/word"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="aaaaaaaaa" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:id="@+id/_en"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="**********" />
<TextView
android:id="@+id/_am"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="+++++++++" />
</LinearLayout>
<TextView
android:id="@+id/meaning"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="ddddddddddd" />
</LinearLayout>
You can fine-tune the rest of the text arrangement.
怪我咯2017-04-18 09:15:15
Just use the weight of linearLayout. The item root layout is a horizontal linearLayout, and the sublayout weights are all 1. The second sublayout is a vertical linearLayout, and its sublayouts are two textViews with a weight of 1.
However, it is best not to use weight if you can. Abuse will cause performance problems.