Android设计-RelativeLayout(背景色)

发布于 2024-12-29 11:15:40 字数 9178 浏览 1 评论 0原文

我有以下相对布局,但我想改进它。 (做出一个漂亮的设计)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    android:id="@+navigate/RLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ABABAB"
    xmlns:android="http://schemas.android.com/apk/res/android"
    >
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:textStyle="bold"
        android:id="@+id/hcorpo" 
        android:layout_centerHorizontal="true"
        android:src="@drawable/hcorpo"
        android:layout_marginTop="15dp" />.
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:textStyle="bold|italic"
        android:textColor="#000000"
        android:id="@+id/hotelinfos"
        android:layout_below="@+id/hcorpo"
        android:layout_alignLeft="@+id/hcorpo" 
        android:layout_marginTop="10dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:textStyle="bold"
        android:textColor="#000000"
        android:id="@+id/hotelname"
        android:layout_below="@+id/hotelinfos"
        android:layout_alignLeft="@+id/hotelinfos" 
        android:layout_marginTop="10dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:textColor="#000000"
        android:id="@+id/hoteladdress"
        android:layout_below="@+id/hotelname"
        android:layout_alignLeft="@+id/hotelname" 
        android:layout_marginTop="10dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:id="@+id/hotelphone"
        android:layout_below="@+id/hoteladdress"
        android:layout_alignLeft="@+id/hoteladdress" 
        android:layout_marginTop="10dp"
        android:textColor="#12C"
        android:textStyle="bold|italic"
        android:onClick="onClick"
        android:clickable="true" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:textColor="#12C"
        android:onClick="onClick"
        android:clickable="true"
        android:textStyle="bold|italic"
        android:id="@+id/hotelemail"
        android:layout_below="@+id/hotelphone"
        android:layout_alignLeft="@+id/hotelphone"
        android:layout_marginTop="10dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:textColor="#000000"
        android:textStyle="bold|italic"
        android:id="@+id/bookinginfos"
        android:layout_below="@+id/hotelemail"
        android:layout_alignLeft="@+id/hotelemail"
        android:layout_marginTop="20dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:textColor="#000000"
        android:id="@+id/pnr"
        android:layout_below="@+id/bookinginfos"
        android:layout_alignLeft="@+id/bookinginfos" 
        android:layout_marginTop="10dp"
        android:layout_marginRight="10dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:textColor="#000000"
        android:id="@+id/segmentCode"
        android:layout_below="@+id/bookinginfos"
        android:layout_toRightOf="@+id/pnr"
        android:layout_marginTop="10dp"
        android:layout_marginRight="20dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:textColor="#000000"
        android:id="@+id/checkin"
        android:layout_below="@+id/pnr"
        android:layout_alignLeft="@+id/pnr" 
        android:layout_marginTop="10dp"
        android:layout_marginRight="10dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:textColor="#000000"
        android:id="@+id/checkout"
        android:layout_below="@+id/pnr"
        android:layout_toRightOf="@+id/checkin"
        android:layout_marginTop="10dp"
        android:layout_marginRight="20dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:textColor="#000000"
        android:id="@+id/nights"    
        android:layout_below="@+id/pnr"
        android:layout_toRightOf="@+id/checkout"
        android:layout_marginTop="10dp"
        android:layout_marginRight="20dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:textColor="#000000"
        android:id="@+id/roomType"
        android:layout_below="@+id/checkin"
        android:layout_alignLeft="@+id/checkin" 
        android:layout_marginTop="10dp"
        android:layout_marginRight="10dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:textColor="#000000"
        android:id="@+id/boardBasis"
        android:layout_below="@+id/roomType"
        android:layout_alignLeft="@+id/roomType"
        android:layout_marginRight="10dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:textColor="#000000"
        android:id="@+id/paxNames"
        android:layout_below="@+id/boardBasis"
        android:layout_alignLeft="@+id/boardBasis" 
        android:layout_marginTop="10dp"
        android:layout_marginRight="10dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:textColor="#000000"
        android:textStyle="bold|italic"
        android:id="@+id/forHotel"
        android:layout_below="@+id/paxNames"
        android:layout_alignLeft="@+id/paxNames" 
        android:layout_marginTop="20dp"
        android:layout_marginRight="10dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:textColor="#000000"
        android:id="@+id/supplierCode"
        android:layout_below="@+id/forHotel"
        android:layout_alignLeft="@+id/forHotel" 
        android:layout_marginTop="10dp"
        android:layout_marginRight="10dp" />
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/picture" 
        android:layout_below="@+id/hcorpo"
        android:layout_alignRight="@+id/hcorpo"
        android:layout_marginTop="10dp"/>
</RelativeLayout>

我想做一些类似 Tripadvisor 应用程序的东西: http://hpics.li/d961aa3 解释:

例如,我想将以下部分放在一个漂亮的白色矩形中:

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:textStyle="bold|italic"
        android:textColor="#000000"
        android:id="@+id/hotelinfos"
        android:layout_below="@+id/hcorpo"
        android:layout_alignLeft="@+id/hcorpo" 
        android:layout_marginTop="10dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:textStyle="bold"
        android:textColor="#000000"
        android:id="@+id/hotelname"
        android:layout_below="@+id/hotelinfos"
        android:layout_alignLeft="@+id/hotelinfos" 
        android:layout_marginTop="10dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:textColor="#000000"
        android:id="@+id/hoteladdress"
        android:layout_below="@+id/hotelname"
        android:layout_alignLeft="@+id/hotelname" 
        android:layout_marginTop="10dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:id="@+id/hotelphone"
        android:layout_below="@+id/hoteladdress"
        android:layout_alignLeft="@+id/hoteladdress" 
        android:layout_marginTop="10dp"
        android:textColor="#12C"
        android:textStyle="bold|italic"
        android:onClick="onClick"
        android:clickable="true" />

我应该使用另一种背景颜色创建一个新的RelativeLayout吗?

任何帮助表示赞赏!

I've the following RelativeLayout but i would like to improve it. (make a nice design)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    android:id="@+navigate/RLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ABABAB"
    xmlns:android="http://schemas.android.com/apk/res/android"
    >
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:textStyle="bold"
        android:id="@+id/hcorpo" 
        android:layout_centerHorizontal="true"
        android:src="@drawable/hcorpo"
        android:layout_marginTop="15dp" />.
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:textStyle="bold|italic"
        android:textColor="#000000"
        android:id="@+id/hotelinfos"
        android:layout_below="@+id/hcorpo"
        android:layout_alignLeft="@+id/hcorpo" 
        android:layout_marginTop="10dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:textStyle="bold"
        android:textColor="#000000"
        android:id="@+id/hotelname"
        android:layout_below="@+id/hotelinfos"
        android:layout_alignLeft="@+id/hotelinfos" 
        android:layout_marginTop="10dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:textColor="#000000"
        android:id="@+id/hoteladdress"
        android:layout_below="@+id/hotelname"
        android:layout_alignLeft="@+id/hotelname" 
        android:layout_marginTop="10dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:id="@+id/hotelphone"
        android:layout_below="@+id/hoteladdress"
        android:layout_alignLeft="@+id/hoteladdress" 
        android:layout_marginTop="10dp"
        android:textColor="#12C"
        android:textStyle="bold|italic"
        android:onClick="onClick"
        android:clickable="true" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:textColor="#12C"
        android:onClick="onClick"
        android:clickable="true"
        android:textStyle="bold|italic"
        android:id="@+id/hotelemail"
        android:layout_below="@+id/hotelphone"
        android:layout_alignLeft="@+id/hotelphone"
        android:layout_marginTop="10dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:textColor="#000000"
        android:textStyle="bold|italic"
        android:id="@+id/bookinginfos"
        android:layout_below="@+id/hotelemail"
        android:layout_alignLeft="@+id/hotelemail"
        android:layout_marginTop="20dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:textColor="#000000"
        android:id="@+id/pnr"
        android:layout_below="@+id/bookinginfos"
        android:layout_alignLeft="@+id/bookinginfos" 
        android:layout_marginTop="10dp"
        android:layout_marginRight="10dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:textColor="#000000"
        android:id="@+id/segmentCode"
        android:layout_below="@+id/bookinginfos"
        android:layout_toRightOf="@+id/pnr"
        android:layout_marginTop="10dp"
        android:layout_marginRight="20dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:textColor="#000000"
        android:id="@+id/checkin"
        android:layout_below="@+id/pnr"
        android:layout_alignLeft="@+id/pnr" 
        android:layout_marginTop="10dp"
        android:layout_marginRight="10dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:textColor="#000000"
        android:id="@+id/checkout"
        android:layout_below="@+id/pnr"
        android:layout_toRightOf="@+id/checkin"
        android:layout_marginTop="10dp"
        android:layout_marginRight="20dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:textColor="#000000"
        android:id="@+id/nights"    
        android:layout_below="@+id/pnr"
        android:layout_toRightOf="@+id/checkout"
        android:layout_marginTop="10dp"
        android:layout_marginRight="20dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:textColor="#000000"
        android:id="@+id/roomType"
        android:layout_below="@+id/checkin"
        android:layout_alignLeft="@+id/checkin" 
        android:layout_marginTop="10dp"
        android:layout_marginRight="10dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:textColor="#000000"
        android:id="@+id/boardBasis"
        android:layout_below="@+id/roomType"
        android:layout_alignLeft="@+id/roomType"
        android:layout_marginRight="10dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:textColor="#000000"
        android:id="@+id/paxNames"
        android:layout_below="@+id/boardBasis"
        android:layout_alignLeft="@+id/boardBasis" 
        android:layout_marginTop="10dp"
        android:layout_marginRight="10dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:textColor="#000000"
        android:textStyle="bold|italic"
        android:id="@+id/forHotel"
        android:layout_below="@+id/paxNames"
        android:layout_alignLeft="@+id/paxNames" 
        android:layout_marginTop="20dp"
        android:layout_marginRight="10dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:textColor="#000000"
        android:id="@+id/supplierCode"
        android:layout_below="@+id/forHotel"
        android:layout_alignLeft="@+id/forHotel" 
        android:layout_marginTop="10dp"
        android:layout_marginRight="10dp" />
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/picture" 
        android:layout_below="@+id/hcorpo"
        android:layout_alignRight="@+id/hcorpo"
        android:layout_marginTop="10dp"/>
</RelativeLayout>

I would like to do something like the tripadvisor app: http://hpics.li/d961aa3
explanation:

For example i would like to put the following part in a nice white rectangle:

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:textStyle="bold|italic"
        android:textColor="#000000"
        android:id="@+id/hotelinfos"
        android:layout_below="@+id/hcorpo"
        android:layout_alignLeft="@+id/hcorpo" 
        android:layout_marginTop="10dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:textStyle="bold"
        android:textColor="#000000"
        android:id="@+id/hotelname"
        android:layout_below="@+id/hotelinfos"
        android:layout_alignLeft="@+id/hotelinfos" 
        android:layout_marginTop="10dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:textColor="#000000"
        android:id="@+id/hoteladdress"
        android:layout_below="@+id/hotelname"
        android:layout_alignLeft="@+id/hotelname" 
        android:layout_marginTop="10dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:id="@+id/hotelphone"
        android:layout_below="@+id/hoteladdress"
        android:layout_alignLeft="@+id/hoteladdress" 
        android:layout_marginTop="10dp"
        android:textColor="#12C"
        android:textStyle="bold|italic"
        android:onClick="onClick"
        android:clickable="true" />

Should i create a new RelativeLayout with another background color?

Any help is appreciated !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

长伴 2025-01-05 11:15:40

要在任何布局中获得圆角矩形作为背景,您可以使用 9 个补丁 PNG 图像或使用形状类来创建自定义可绘制对象。

请查看下面我的示例代码,它可能对您有用。

ma​​in.xml 在布局文件夹中

<?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" >
    <LinearLayout android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_margin="20dip"
        android:orientation="vertical"
        android:background="@drawable/bg">
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Testing white rectangle"
            android:textColor="#f00"
            android:padding="10dip"
            android:textSize="25dip" />
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Testing white rectangle"
            android:textColor="#0f0"
            android:padding="10dip"
            android:textSize="25dip" />
    </LinearLayout>
</LinearLayout>

bg.xml 在可绘制文件夹中

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">   
    <solid android:color="#fff"/>    
    <corners android:bottomLeftRadius="7dip"
        android:topRightRadius="7dip"
        android:topLeftRadius="7dip"
        android:bottomRightRadius="7dip" />
</shape>

Java 文件

public class WhiteRectangle extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

输出为

白色矩形作为背景

To get round rectangles as background in any layout, you can use 9 patch PNG images or use shape class to create custom drawables.

Just check my sample code below, it may useful to you.

main.xml in layout folder

<?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" >
    <LinearLayout android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_margin="20dip"
        android:orientation="vertical"
        android:background="@drawable/bg">
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Testing white rectangle"
            android:textColor="#f00"
            android:padding="10dip"
            android:textSize="25dip" />
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Testing white rectangle"
            android:textColor="#0f0"
            android:padding="10dip"
            android:textSize="25dip" />
    </LinearLayout>
</LinearLayout>

bg.xml in drawable folder

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">   
    <solid android:color="#fff"/>    
    <corners android:bottomLeftRadius="7dip"
        android:topRightRadius="7dip"
        android:topLeftRadius="7dip"
        android:bottomRightRadius="7dip" />
</shape>

Java file

public class WhiteRectangle extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

The output is

White rectangle as background

陌路终见情 2025-01-05 11:15:40

您可以创建内部线性/相对布局,并将背景设置为白色。 :)

You can create an inner linear/relative layout with background set to white. :)

铁轨上的流浪者 2025-01-05 11:15:40

用这个

android:background="@drawable/img_list_background_repeater" 

use this

android:background="@drawable/img_list_background_repeater" 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文