Android XML文件中的相对布局
我的XML文件中有以下代码:Android XML文件中的相对布局,android,android-layout,Android,Android Layout,我的XML文件中有以下代码: <LinearLayout android:layout_width="fill_parent" android:layout_height="60dip" android:layout_marginLeft="13dp" android:layout_marginRight="13dp" android:layout_marginTop="20dp"
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="60dip"
android:layout_marginLeft="13dp"
android:layout_marginRight="13dp"
android:layout_marginTop="20dp"
android:background="@color/white"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/name_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/pic"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginLeft="6dp" />
<EditText
android:id="@+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_alignRight="@id/pic" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/phone_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/phone_pic"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginLeft="6dp"
android:layout_weight="0.15" />
<EditText
android:id="@+id/phone_number"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_alignRight="@id/phone_pic" />
</RelativeLayout>
</LinearLayout>
我希望
RelativeLayout
中的ImageView
和EditText
字段以及ImageView
右侧的EEditText
字段。但是,当我检查图形布局时,编辑文本
和图像视图
被放置在相对布局
以及线性布局
之外。我做错了什么?如何更正?在布局中更改这些代码行这是错误的
android:layout_alignRight="@id/phone_pic"
android:layout_alignRight="@id/pic"
把这些写在下面几行
android:layout_alignRight="@+id/phone_pic"
android:layout_alignRight="@+id/pic"
在布局中更改这些代码行这是错误的
android:layout_alignRight="@id/phone_pic"
android:layout_alignRight="@id/pic"
把这些写在下面几行
android:layout_alignRight="@+id/phone_pic"
android:layout_alignRight="@+id/pic"
为什么不将您的
RelativeLayout
替换为水平LinearLayout
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="60dip"
android:layout_marginLeft="13dp"
android:layout_marginRight="13dp"
android:layout_marginTop="20dp"
android:background="@color/white"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/name_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="@+id/pic"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginLeft="6dp" />
<EditText
android:id="@+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp" />
</LinearLayout>
<LinearLayout
android:id="@+id/phone_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="@+id/phone_pic"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginLeft="6dp"
android:layout_weight="0.15" />
<EditText
android:id="@+id/phone_number"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp" />
</LinearLayout>
</LinearLayout>
为什么不用水平
线性布局替换您的相对布局
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="60dip"
android:layout_marginLeft="13dp"
android:layout_marginRight="13dp"
android:layout_marginTop="20dp"
android:background="@color/white"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/name_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="@+id/pic"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginLeft="6dp" />
<EditText
android:id="@+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp" />
</LinearLayout>
<LinearLayout
android:id="@+id/phone_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="@+id/phone_pic"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginLeft="6dp"
android:layout_weight="0.15" />
<EditText
android:id="@+id/phone_number"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp" />
</LinearLayout>
</LinearLayout>
尝试使用属性android:layout\u-toRightOf
将此视图的左边缘定位到给定锚点的右侧
视图ID。容纳此视图的左边缘和视图的右边缘
锚定视图
所以试试这个:
<RelativeLayout
android:id="@+id/name_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/pic"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginLeft="6dp" />
<EditText
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_toRightOf="@+id/pic" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/phone_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/phone_pic"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginLeft="6dp"
android:layout_weight="0.15" />
<EditText
android:id="@+id/phone_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_toRightOf="@+id/phone_pic" />
</RelativeLayout>
</LinearLayout>
如果你想用一个例子更好地理解,这里有一个给你。还有一个源代码,您可以进行测试 尝试使用属性android:layout\u-toRightOf
将此视图的左边缘定位到给定锚点的右侧
视图ID。容纳此视图的左边缘和视图的右边缘
锚定视图
所以试试这个:
<RelativeLayout
android:id="@+id/name_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/pic"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginLeft="6dp" />
<EditText
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_toRightOf="@+id/pic" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/phone_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/phone_pic"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginLeft="6dp"
android:layout_weight="0.15" />
<EditText
android:id="@+id/phone_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_toRightOf="@+id/phone_pic" />
</RelativeLayout>
</LinearLayout>
如果你想用一个例子更好地理解,这里有一个给你。还有一个源代码,您可以进行测试 这将帮助您
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_launcher" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/imageView1"
android:ems="10" >
<requestFocus />
</EditText>
</RelativeLayout>
这将帮助您
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_launcher" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/imageView1"
android:ems="10" >
<requestFocus />
</EditText>
</RelativeLayout>
您可以试试这段代码
<?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="60dp"
android:layout_marginLeft="13dp"
android:layout_marginRight="13dp"
android:layout_marginTop="20dp"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/name_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/pic"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:src="@drawable/ic_launcher" />
<EditText
android:id="@+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_toRightOf="@id/pic" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/phone_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/phone_pic"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:src="@drawable/ic_launcher" />
<EditText
android:id="@+id/phone_number"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_toRightOf="@id/phone_pic" />
</RelativeLayout>
您可以试试这段代码
<?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="60dp"
android:layout_marginLeft="13dp"
android:layout_marginRight="13dp"
android:layout_marginTop="20dp"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/name_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/pic"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:src="@drawable/ic_launcher" />
<EditText
android:id="@+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_toRightOf="@id/pic" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/phone_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/phone_pic"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:src="@drawable/ic_launcher" />
<EditText
android:id="@+id/phone_number"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_toRightOf="@id/phone_pic" />
</RelativeLayout>
正如罗格格先生所说,试试安卓系统:它的布局将起作用。但是,还必须对线性布局属性进行某些更改。您已指定android:layout\u height=“60dip”
这会导致连续的相对布局被隐藏。使其填充父对象并设置布局。它会起作用的
同样,对于图像视图,指定一个src,如下所示
android:src=“@drawable/someimage”
谢谢和问候,
Rajamanickem.S正如rogcg先生所说,试试android:它的布局将起作用。但是,还必须对线性布局属性进行某些更改。您已指定android:layout\u height=“60dip”
这会导致连续的相对布局被隐藏。使其填充父对象并设置布局。它会起作用的
同样,对于图像视图,指定一个src,如下所示
android:src=“@drawable/someimage”
谢谢和问候,
Rajamanickem.SLo,再试一次,你没有改变任何事情Lo,再试一次,你没有改变任何事情