[英]Error Adding Child View on RelativeLayout
I having problems adding child views after a running relative layout. 我在运行相对布局后添加子视图时遇到问题。 What I know, when I add another view into the layout, I just place the xml code at the bottom of the last view on the layout.
我所知道的,当我向布局中添加另一个视图时,我只是将xml代码放在布局上最后一个视图的底部。 Then add the positioning.
然后添加定位。
I want to add this code under rating bar: 我想在评分栏下添加以下代码:
<TextView
android:id="@+id/viewSeparat2"
android:layout_below="@+id/ratingBar1"
android:layout_width="fill_parent"
android:layout_height="2px"
android:background="#DADADA" />
XML Layout: XML布局:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@drawable/separator"
android:dividerPadding="12dip"
android:showDividers="middle"
android:layout_margin="10dip"
>
<ImageView
android:id="@+id/itemItem"
android:src="@drawable/content_picture"
android:tag="image_item_grid_image"
android:background="@drawable/layout_bg"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:layout_height="wrap_content"
android:padding="10dip"
android:contentDescription="Desc"
android:scaleType="fitCenter" />
<TextView
android:id="@+id/textPid"
android:layout_below="@+id/viewSeparator"
android:typeface="sans"
android:textSize="15sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dip"
android:text="TextView" />
<TextView
android:id="@+id/textName"
android:typeface="sans"
android:textSize="15sp"
android:layout_below="@+id/textPid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dip"
android:text="TextView" />
<TextView
android:id="@+id/textSellingPrice"
android:typeface="sans"
android:textSize="15sp"
android:layout_below="@+id/textName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dip"
android:text="TextView" />
<RatingBar
android:id="@+id/ratingBar1"
android:typeface="sans"
android:textSize="15sp"
android:layout_below="@+id/textSellingPrice"
android:layout_width="wrap_content"
android:layout_margin="10dip"
android:layout_height="wrap_content" />
<ImageButton
android:id="@+id/addTOCart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/itemItem"
android:background="?android:attr/selectableItemBackground"
style="?android:attr/borderlessButtonStyle"
android:layout_centerHorizontal="true"
android:src="@drawable/add_to_cart" />
<TextView
android:id="@+id/viewSeparator"
android:layout_below="@+id/addTOCart"
android:layout_width="fill_parent"
android:layout_height="2px"
android:background="#DADADA" />
<TextView
android:id="@+id/viewSeparat2"
android:layout_below="@+id/ratingBar1"
android:layout_width="fill_parent"
android:layout_height="2px"
android:background="#DADADA" />
</RelativeLayout >
</ScrollView >
UPDATE: 更新:
I am getting error when I add the viewSeparat2
to ratingBar1
. 当我加我得到错误
viewSeparat2
到ratingBar1
。
Maybe you wanted to do : 也许您想做:
android:id="@+id/viewSeparat2"
android:layout_below="@id/viewSeparator"
See this 看到这个
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dip"
android:divider="@drawable/seperator"
android:dividerPadding="12dip"
android:showDividers="middle" >
<ImageView
android:id="@+id/itemItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:padding="10dip"
android:scaleType="fitCenter"
android:src="@drawable/ic_launcher"
android:tag="image_item_grid_image" />
<TextView
android:id="@+id/textPid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/viewSeparator"
android:layout_margin="10dip"
android:text="TextView"
android:textSize="15sp"
android:typeface="sans" />
<TextView
android:id="@+id/textName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textPid"
android:layout_margin="10dip"
android:text="TextView"
android:textSize="15sp"
android:typeface="sans" />
<TextView
android:id="@+id/textSellingPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textName"
android:layout_margin="10dip"
android:text="TextView"
android:textSize="15sp"
android:typeface="sans" />
<RatingBar
android:id="@+id/ratingBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textSellingPrice"
android:layout_margin="10dip"
android:textSize="15sp"
android:typeface="sans" />
<TextView
android:id="@+id/viewSeparat2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/ratingBar1"
android:text="jhadgjad" />
<ImageButton
android:id="@+id/addTOCart"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/itemItem"
android:layout_centerHorizontal="true"
android:src="@drawable/ic_action_call"/>
<TextView
android:id="@+id/viewSeparator"
android:layout_width="fill_parent"
android:layout_height="2px"
android:layout_below="@+id/addTOCart"
android:background="#DADADA" />
<TextView
android:id="@+id/viewSeparat2"
android:layout_width="fill_parent"
android:layout_height="2px"
android:layout_below="@+id/viewSeparat2"
android:background="#DADADA" />
</RelativeLayout>
</ScrollView>
LinearLayout best suits your case, just set orientation property of LinearLayout to vertical and than remove android:layout_below
from every UI component from xml and add components in the sequence you want to appear in screen. LinearLayout最适合您的情况,只需将LinearLayout的
android:layout_below
属性设置为vertical,然后从xml的每个UI组件中删除android:layout_below
要在屏幕上显示的顺序添加组件。 although LinearLayout is slow but in your use case it suits you best enter code here
虽然LinearLayout速度很慢,但是在您的用例中,它最适合您
enter code here
FYI: You may already know, ScrollView
can have only and only one child(but that child could have its own sub childs) 仅供参考:您可能已经知道,
ScrollView
只能有一个孩子(但是该孩子可以有自己的子孩子)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.