简体   繁体   English

Android布局设计:使用LinearLayout和相对布局

[英]Android layout design : Using LinearLayout and Relative layout

I want to have a layout exactly similar to one below in image. 我想要一个布局与下面的图片完全相似。 I've tried the below code but it is not coming. 我已经尝试了下面的代码,但是没有来。 Can someone help me in getting this layout. 有人可以帮助我获得此布局。

需要版面

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:padding="6dip" >

    <TextView
        android:id="@+id/firstLine"
        android:layout_width="fill_parent"
        android:layout_height="26dip"
        android:ellipsize="marquee"
        android:singleLine="true"
        android:text="Ali Connors"
        android:textSize="12sp" />

    <TextView
        android:id="@+id/secondLine"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/firstLine"
        android:gravity="center_vertical"
        android:text="Brunch this weekend?"
        android:textSize="16sp" />

    <TextView
        android:gravity="right"
        android:id="@+id/rightTime"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="15m"
        android:textSize="16sp" />

</RelativeLayout>

try the following: 尝试以下方法:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <View
        android:layout_width="match_parent"
        android:layout_height="4dp"
        android:background="#ED262A" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="6dp">

        <TextView
            android:id="@+id/firstLine"
            android:layout_width="fill_parent"
            android:layout_height="26dp"
            android:layout_alignParentLeft="true"
            android:layout_marginTop="5dp"
            android:ellipsize="marquee"
            android:singleLine="true"
            android:text="Ali Connors"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/secondLine"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/firstLine"
            android:gravity="center_vertical"
            android:text="Brunch this weekend?"
            android:textSize="15sp" />

        <TextView
            android:id="@+id/thirdLine"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@id/secondLine"
            android:drawablePadding="6dp"
            android:drawableRight="@android:drawable/star_off"
            android:gravity="center_vertical"
            android:text="I will be in the place"
            android:textColor="#A4A18E"
            android:textSize="14sp" />


        <TextView
            android:id="@+id/rightTime"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:padding="5dp"
            android:layout_alignParentRight="true"
            android:gravity="top|right"
            android:text="15m"
            android:textSize="16sp" />

    </RelativeLayout>

</LinearLayout>

在此处输入图片说明

Try this. 尝试这个。

    <TextView
    android:text="15m"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:id="@+id/rightTime"
    android:textSize="16sp"/>

Design your Layout as below: 设计布局如下:

<?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:orientation="vertical">

    <View
        android:layout_width="match_parent"
        android:layout_height="4dp"
        android:background="#FF4081" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="16dp">

        <TextView
            android:id="@+id/rightTime"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:text="15m"
            android:textSize="14sp"
            android:textColor="#727272"/>

        <TextView
            android:id="@+id/firstLine"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_toLeftOf="@id/rightTime"
            android:layout_marginRight="8dp"
            android:maxLines="1"
            android:ellipsize="end"
            android:text="Ali Connors"
            android:textSize="16sp"
            android:textColor="#000000"/>

        <TextView
            android:id="@+id/secondLine"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/firstLine"
            android:layout_marginTop="2dp"
            android:text="Brunch this weekend?"
            android:textSize="16sp"
            android:textColor="#000000"
            android:maxLines="1"
            android:ellipsize="end" />

        <ImageView
            android:id="@+id/image_star"
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:layout_below="@id/secondLine"
            android:layout_alignParentRight="true"
            android:background="@android:drawable/star_big_off" />

        <TextView
            android:id="@+id/thirdLine"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/secondLine"
            android:layout_toLeftOf="@id/image_star"
            android:layout_marginTop="4dp"
            android:layout_marginRight="16dp"
            android:text="I will be in your neighborhood doing some errands....."
            android:textColor="#727272"
            android:textSize="14sp"
            android:maxLines="1"
            android:ellipsize="end" />
    </RelativeLayout>
</LinearLayout>

Output: 输出:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM