这可能是一个非常愚蠢的问题,但我对这些列表项的布局XML有几个问题
我知道有三个文本视图,但他们是如何在最后一行留下缩进的?另外,它们是如何导致第二个textview在一定数量的行之后换行的?
如果有人可以发布样本XML,那也很棒。
答案 0 :(得分:0)
最后一个TextView要么布局对齐到右边(layout_gravity),要么它匹配父宽度并且它的重力(不是布局一个,但它自己的)到右边。
要椭圆化第二个TextView,给它一个有效的高度,然后将ellipsize属性设置为end。
答案 1 :(得分:0)
使用以下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>
答案 2 :(得分:0)
配方是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>
(您可以用TextView
替换ListView
)
编辑:我想每个人都在这里给你一些解决方案:)。