如何创建布局,以便Textview应该在android中自动调整

时间:2014-09-15 07:25:04

标签: android

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="100dip"
    android:background="#fff"
    android:orientation="horizontal" >

    <com.lociiapp.utils.RoundedImageView
        android:id="@+id/notificationuserimage"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_margin="20dp"
        android:layout_marginBottom="10dip" />

    <LinearLayout
        android:id="@+id/motherLayout"
        android:layout_width="wrap_content"
        android:layout_height="108dp"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignTop="@+id/notificationuserimage"
            android:layout_toEndOf="@+id/notificationuserimage"
            android:layout_toRightOf="@+id/notificationuserimage"
            android:paddingBottom="10dp"
            android:text="Request for traveling"
            android:textColor="#282e36"
            android:textSize="23px"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/desc"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/title"
            android:layout_alignStart="@+id/title"
            android:layout_below="@+id/title"
            android:text="asd has requested to travel with you"
            android:textColor="#282e36"
            android:textSize="23px" />

        <LinearLayout
            android:id="@+id/motherLayout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/imageView1"
                android:layout_width="wrap_content"
                android:layout_height="30dip"
                android:layout_alignBottom="@+id/notificationuserimage"
                android:layout_toEndOf="@+id/notificationuserimage"
                android:layout_toRightOf="@+id/notificationuserimage"
                android:background="#10a7a2"
                android:text="Accept" />

            <View
                android:id="@+id/view1"
                android:layout_width="1dp"
                android:layout_height="10dp"
                android:background="#feffff" />

            <Button
                android:id="@+id/imageView2"
                android:layout_width="wrap_content"
                android:layout_height="30dip"
                android:layout_alignTop="@+id/imageView1"
                android:layout_toEndOf="@+id/imageView1"
                android:layout_toRightOf="@+id/imageView1"
                android:background="#10a7a2"
                android:text="Reject" />

            <TextView
                android:id="@+id/rejectedrequest"
                android:layout_width="wrap_content"
                android:layout_height="40dip"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_alignTop="@+id/revresetime"
                android:singleLine="true"
                android:text="Rejected"
                android:visibility="invisible" />

            <ImageView
                android:id="@+id/runnimage"
                android:layout_width="wrap_content"
                android:layout_height="25dip"
                android:layout_alignTop="@+id/revresetime"
                android:layout_toLeftOf="@+id/rejectedrequest"
                android:layout_toStartOf="@+id/rejectedrequest"
                android:src="@drawable/drive"
                android:visibility="invisible" />

            <TextView
                android:id="@+id/revresetime"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBottom="@+id/imageView2"
                android:layout_alignTop="@+id/imageView2"
                android:layout_toEndOf="@+id/imageView2"
                android:layout_toRightOf="@+id/imageView2"
                android:gravity="left|center_vertical"
                android:text="Just 5 Minute Ago"
                android:textColor="#8f939b"
                android:textSize="23px" />
        </LinearLayout>
    </LinearLayout>

</LinearLayout>

这是我的List List for List视图项,我可以在Listview中显示项目。我的当前屏幕看起来像enter image description here

DeSire Screen:enter image description here

1.我无法设置日期和时间2.图像中没有图像日期的宽度列表项较少向左移动时应根据文本自动调整我已经尝试了很多无法控制日期和时间textview自动设置

1 个答案:

答案 0 :(得分:0)

尝试使用android:gravity标记来对齐textViews并设置paddings以分隔它们:

    <TextView
                android:id="@+id/yourId"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_span="3"

                android:gravity="center_horizontal"

   />  



// android:gravity="left" to align to left
//  android:gravity="right" to align to right