Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Android XML文件中的两个文本视图后面设置背景图像_Android_Xml_Layout_Android Relativelayout - Fatal编程技术网

在Android XML文件中的两个文本视图后面设置背景图像

在Android XML文件中的两个文本视图后面设置背景图像,android,xml,layout,android-relativelayout,Android,Xml,Layout,Android Relativelayout,如果您对Android中的XML布局有任何了解,请快速浏览一下。我有下面的XML布局,它显示一个图像,然后在下面显示一个地址和电话号码 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:background="@drawable/mainbackground"

如果您对Android中的XML布局有任何了解,请快速浏览一下。我有下面的XML布局,它显示一个图像,然后在下面显示一个地址和电话号码

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:background="@drawable/mainbackground"
          android:layout_width="fill_parent" 
          android:layout_height="fill_parent"
          android:orientation="vertical" 
          android:id="@+id/view1">
   <ImageView android:id="@+id/imageView1" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:layout_centerHorizontal="true"
    android:layout_marginTop="50px"
    android:padding="12dip"
    android:background="#FFFFFF">
  </ImageView>
  <TextView android:id="@+id/addressView" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_below="@id/imageView1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20px"
        android:padding="12dip"
        android:textColor="#000000"
        android:background="#FFFFFF">
   </TextView>
   <TextView android:id="@+id/phoneView"
        android:textColor="#0000FF" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_below="@id/addressView"
        android:layout_centerHorizontal="true"
        android:padding="12dip"
        android:background="#FFFFFF">
    </TextView>
</RelativeLayout>

目前,我只是使用android:padding和android:background标记在ImageView和两个TextView后面设置一个白色背景。对于图像视图,这非常适合我。对于文本视图,它们显然有两个单独的边框/背景。但是,我想在两个文本视图后面设置一个白色背景图像,而不是两个单独的边框/背景。有关我希望最终结果的详细信息,请参见此图:


我只是不知道如何“包装”这两个文本视图的白色框。显然,android:padding和android:background标签可能不是实现这一点的方法。如果有人能帮忙,我们将不胜感激

将图像设置为同时包含文本视图和您已设置的LinearLayout的背景。

将图像设置为同时包含文本视图和您已设置的LinearLayout的背景。


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:background="@drawable/button_blue"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical"
                android:id="@+id/view1">
    <ImageView android:id="@+id/imageView1"
               android:layout_height="wrap_content"
               android:layout_width="wrap_content"
               android:layout_centerHorizontal="true"
               android:layout_marginTop="50px"
               android:padding="12dip"
               android:background="#FFFFFF">
    </ImageView>

    <LinearLayout
            android:id="commonBackgroundImage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#FFFFFF"
            android:layout_below="@id/imageView1"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="20px"
            android:padding="12dip"
            android:orientation="vertical">

        <TextView android:id="@+id/addressView"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:textColor="#000000"
                  android:text="text1">
        </TextView>
        <TextView android:id="@+id/phoneView"
                  android:textColor="#0000FF"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:text="text2">
        </TextView>

    </LinearLayout>
</RelativeLayout>


谢谢您的帖子!我已经把我的布局改成了线性布局,并且尝试了一些事情,但是我仍然和以前一样。你能不能提供更多的细节,或者你的意思的一个例子(基于我的代码)?没关系,我看错了你的评论。。我以为你想把我的整个布局改成线性布局。我现在明白了!再次感谢:)谢谢你的帖子!我已经把我的布局改成了线性布局,并且尝试了一些事情,但是我仍然和以前一样。你能不能提供更多的细节,或者你的意思的一个例子(基于我的代码)?没关系,我看错了你的评论。。我以为你想把我的整个布局改成线性布局。我现在明白了!再次感谢:)