这可能是一个非常愚蠢的问题,但我对布局XML是什么样子,这些列表项什么布局XML看起来像这样?
我知道有三个textviews几个问题,但他们是如何离开缩进最后一行?另外,它们是如何导致第二个textview在一定数量的行之后进行换行的?
如果有人可以发布样本XML,那也太棒了。
这可能是一个非常愚蠢的问题,但我对布局XML是什么样子,这些列表项什么布局XML看起来像这样?
我知道有三个textviews几个问题,但他们是如何离开缩进最后一行?另外,它们是如何导致第二个textview在一定数量的行之后进行换行的?
如果有人可以发布样本XML,那也太棒了。
使用以下xml,最后一个textview向右。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:maxLines="2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:maxLines="5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:layout_gravity="right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
最后一个TextView是右对齐的布局(layout_gravity),或者它与父宽度匹配并且具有它的引力(不是布局之一,但它自己)。
要省略第二个TextView,给它一个有效的高度,然后设置ellipsize属性结束。
配方是ScrollView + TextView + LinearLayout + gravity。 对于相同的外观,检查:
<?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="vertical">
<ScrollView
android:id="@+id/sv"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:textSize="24dip"
android:layout_height="wrap_content"
android:text="Morning"
/>
<TextView
android:layout_width="fill_parent"
android:textSize="14dip"
android:layout_height="wrap_content"
android:text="Layout container for a view hierarchy that can be scrolled by the user, allowing it to be larger than the physical display. A ScrollView is a FrameLayout, meaning you should place one child in it containing the entire contents to scroll; this child may itself be a layout manager with a complex hierarchy of objects. A child that is often used is a LinearLayout in a vertical orientation, presenting a vertical array of top-level items that the user can scroll through. "
/>
<TextView
android:layout_width="fill_parent"
android:textSize="12dip"
android:layout_height="wrap_content"
android:text="Morning"
android:gravity="right"
/>
<TextView
android:layout_width="fill_parent"
android:textSize="24dip"
android:layout_height="wrap_content"
android:text="Morning"
/>
<TextView
android:layout_width="fill_parent"
android:textSize="14dip"
android:layout_height="wrap_content"
android:text="Layout container for a view hierarchy that can be scrolled by the user, allowing it to be larger than the physical display. A ScrollView is a FrameLayout, meaning you should place one child in it containing the entire contents to scroll; this child may itself be a layout manager with a complex hierarchy of objects. A child that is often used is a LinearLayout in a vertical orientation, presenting a vertical array of top-level items that the user can scroll through. "
/>
<TextView
android:layout_width="fill_parent"
android:textSize="12dip"
android:layout_height="wrap_content"
android:text="Morning"
android:gravity="right"
/>
<TextView
android:layout_width="fill_parent"
android:textSize="24dip"
android:layout_height="wrap_content"
android:text="Morning"
/>
<TextView
android:layout_width="fill_parent"
android:textSize="14dip"
android:layout_height="wrap_content"
android:text="Layout container for a view hierarchy that can be scrolled by the user, allowing it to be larger than the physical display. A ScrollView is a FrameLayout, meaning you should place one child in it containing the entire contents to scroll; this child may itself be a layout manager with a complex hierarchy of objects. A child that is often used is a LinearLayout in a vertical orientation, presenting a vertical array of top-level items that the user can scroll through. "
/>
<TextView
android:layout_width="fill_parent"
android:textSize="12dip"
android:layout_height="wrap_content"
android:text="Morning"
android:gravity="right"
/>
</LinearLayout>
</ScrollView>
</LinearLayout>
编辑(您可以通过一个ListView
更换TextView
S):我想每个人都在这里给你一个位解决方案的:)。
它相当自定义的listview。使用重力属性将最后一个文本设置为正确。至于将textview限制为x行,请使用setMaxLines(x); – Raunak