2011-09-08 190 views
0

這可能是一個非常愚蠢的問題,但我對佈局XML是什麼樣子,這些列表項什麼佈局XML看起來像這樣?

enter image description here

我知道有三個textviews幾個問題,但他們是如何離開縮進最後一行?另外,它們是如何導致第二個textview在一定數量的行之後進行換行的?

如果有人可以發佈樣本XML,那也太棒了。

+0

它相當自定義的listview。使用重力屬性將最後一個文本設置爲正確。至於將textview限制爲x行,請使用setMaxLines(x); – Raunak

回答

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> 
0

最後一個TextView是右對齊的佈局(layout_gravity),或者它與父寬度匹配並且具有它的引力(不是佈局之一,但它自己)。

要省略第二個TextView,給它一個有效的高度,然後設置ellipsize屬性結束。

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> 

編輯(您可以通過一個ListView更換TextView S):我想每個人都在這裏給你一個位解決方案的:)。

相關問題