2015-09-09 28 views
0

我有我的列表视图中项目的布局。我在列表视图中使用的每个项目都使用此布局。布局的代码如下:线性布局内相对布局中的文本android

<?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="wrap_content" 
android:background="@color/white" 
android:orientation="horizontal" 
android:id="@+id/view"> 


<RelativeLayout 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="10dp" 
    android:layout_marginRight="10dp" 
    android:layout_marginTop="10dp" 
    android:layout_weight="40" 
    android:paddingBottom="10dp" 
    android:paddingTop="10dp" > 

    <TextView 
     android:id="@+id/messages_list_element_textview_header" 
     style="@style/category_list_textview" 
     android:layout_alignParentLeft="true" 
     android:padding="5dp" 
     android:maxLines="5" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:textColor="@color/bg_login" 
     android:textSize="14sp" 
     android:text="some text" 
     android:inputType="textImeMultiLine" /> 

    <TextView 
     android:id="@+id/messages_list_element_textview_view" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:layout_centerVertical="true" 
     android:layout_below="@+id/messages_list_element_textview_header" 
     android:textColor="@color/bg_login" 
     android:textSize="12sp" 
     android:text="some text" 
     android:layout_marginLeft="5dp" 
     android:padding="5dp" /> 

</RelativeLayout> 
<TextView 
    android:id="@+id/messages_list_element_name" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="10dp" 
    android:layout_weight="60" 
    android:text="some text" 
    android:padding="5dp"/> 
</LinearLayout> 

我填写与身份证“messages_list_element_textview_header” TextView的文本不换行。我在下面使用的textview('messages_list_element_textview_view')用于显示日期,所以我不想包装它。

有人请指教我如何获得'messages_list_element_textview_header'来包装。

感谢

回答

0

fill_parent

(弃用,在API 8级,并更名为MATCH_PARENT更高)

设置一个小部件的布局FILL_PARENT将迫使它扩大到占据尽可能多的空间,在它被放置的布局元素中可用。它大致等同于将Windows窗体控件的dockstyle设置为Fill。

将顶层布局或控件设置为fill_parent将强制它占据整个屏幕。

wrap_content 

将视图的大小设置为wrap_content将强制它只展开到足以包含它所包含的值(或子控件)。对于控件 - 如文本框(TextView)或图像(ImageView) - 这将包装显示的文本或图像。对于布局元素,它将调整布局大小以适合添加为其子元素的控件/布局。

wrap_content 

将根据您的文字大小和文本数量进行调整。它总是可取的。否则,你可以设定根据您的需要

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/white" 
    android:orientation="horizontal" 
    android:id="@+id/view"> 


    <RelativeLayout 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="10dp" 
    android:layout_marginRight="10dp" 
    android:layout_marginTop="10dp" 
    android:layout_weight="40" 
    android:paddingBottom="10dp" 
    android:id="@+id/relative" 
    android:paddingTop="10dp" > 

    <TextView 
     android:id="@+id/messages_list_element_textview_header" 
     style="@style/category_list_textview" 
     android:layout_alignParentLeft="true" 
     android:padding="5dp" 
     android:maxLines="5" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:textColor="@color/bg_login" 
     android:textSize="14sp" 
     android:text="some text" 
     android:inputType="textImeMultiLine" /> 

    <TextView 
     android:id="@+id/messages_list_element_textview_view" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:layout_centerVertical="true" 
     android:layout_below="@+id/messages_list_element_textview_header" 
     android:textColor="@color/bg_login" 
     android:textSize="12sp" 
     android:text="some text" 
     android:layout_marginLeft="5dp" 
     android:padding="5dp" /> 

</RelativeLayout> 
<TextView 
    android:id="@+id/messages_list_element_name" 
    android:layout_width="0dp" 
    android:layout_below="@+id/relative" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="10dp" 
    android:layout_weight="60" 
    android:text="some text" 
    android:padding="5dp"/> 
</RelativeLayout> 
+0

我不能设置一个固定的高度TextView的外面所需的相关布局包裹dp60dp增加或减少。我不喜欢在相对布局外的任何文字视图效果。 – BountyHunter

+0

@BountyHunter将您的父布局设置为RelativeLayout,并为布局外的TextView提供layout_below – Sridhar

+0

@BountyHunter更新了对此没有多大帮助的回答 – Sridhar