[英]android:layout_below= does not place item below
I have an editText and a textView which I'm attempting to set below an imageView however the parameter android:layout_below= does not place item below. 我有一个editText和一个textView,我试图将其设置在imageView下方,但是参数android:layout_below =不会在下方放置项目。
How might this be avoided? 如何避免这种情况?
Also I'm setting android:layout_alignParentRight="true" on the textView, editText and imageView and that does not seem to be working either. 另外,我在textView,editText和imageView上设置了android:layout_alignParentRight =“ true”,这似乎也不起作用。
<?xml version="1.0" encoding="utf-8"?>
<com.example.project.DragLayer xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher"
android:id="@+id/drag_layer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/black" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="1.0" >
<GridView
android:id="@+id/image_grid_view"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="0.8"
android:background="@color/grid_background"
android:gravity="center"
android:horizontalSpacing="2dip"
android:numColumns="@integer/num_columns"
android:stretchMode="columnWidth"
android:verticalSpacing="2dip" />
<RelativeLayout
android:id="@+id/bottom_part"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
android:layout_weight="0.2"
android:background="@android:color/black"
android:orientation="horizontal"
android:weightSum="1.0" >
<Button
android:id="@+id/button_add_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:onClick="onClickAddImage"
android:text="Add image" />
<com.example.project.DeleteZone
android:id="@+id/delete_zone_view"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center"
android:src="@drawable/delete_zone" />
<FrameLayout
android:id="@+id/image_source_frame"
android:layout_width="80dp"
android:layout_height="200dp"
android:layout_weight="0.5" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:id="@+id/sqwhite"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_gravity="right"
android:layout_marginRight="5dp" />
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/sqwhite"
android:layout_marginRight="5dp" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/editText1"
android:layout_marginRight="5dp"
android:text=""
android:textColor="@android:color/white" />
</RelativeLayout>
</FrameLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</com.example.project.DragLayer>
You are using Linear Layout, if you switch to Relative Layout, android:layout_below
will work. 您使用的是线性布局,如果您切换到相对布局,则android:layout_below
将起作用。
android:layout_alignParentRight="true"
will work for Relative Layout too. android:layout_alignParentRight="true"
也适用于相对布局。
Hope this helps! 希望这可以帮助!
Use RelativeLayout
instead of LinearLayout
inside the following FrameLayout
. 在以下FrameLayout
使用RelativeLayout
而不是LinearLayout
。
<FrameLayout
android:id="@+id/image_source_frame"
...
>
</FrameLayout>
Hope this helps. 希望这可以帮助。
you code perfectly working fine. 您的代码工作正常。 issue is height and width of image. 问题是图像的高度和宽度。 try below code. 尝试下面的代码。
<?xml version="1.0" encoding="utf-8"?>
<com.example.project.DragLayer xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher"
android:id="@+id/drag_layer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/black" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="1.0" >
<GridView
android:id="@+id/image_grid_view"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="0.8"
android:background="@color/grid_background"
android:gravity="center"
android:horizontalSpacing="2dip"
android:numColumns="@integer/num_columns"
android:stretchMode="columnWidth"
android:verticalSpacing="2dip" />
<RelativeLayout
android:id="@+id/bottom_part"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
android:layout_weight="0.2"
android:background="@android:color/black"
android:orientation="horizontal"
android:weightSum="1.0" >
<Button
android:id="@+id/button_add_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:onClick="onClickAddImage"
android:text="Add image" />
<com.example.project.DeleteZone
android:id="@+id/delete_zone_view"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center"
android:src="@drawable/delete_zone" />
<FrameLayout
android:id="@+id/image_source_frame"
android:layout_width="80dp"
android:layout_height="200dp"
android:layout_weight="0.5" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/sqwhite"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="#657654"
android:layout_alignParentRight="true"
android:layout_gravity="right"
android:layout_marginRight="5dp" />
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/sqwhite"
android:background="#843577"
android:layout_marginRight="5dp" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#454544"
android:layout_alignParentRight="true"
android:layout_below="@+id/editText1"
android:layout_marginRight="5dp"
android:text=""
android:textColor="@android:color/white" />
</RelativeLayout>
</FrameLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
You are treating your RelativeLayout (the one with the button, DeleteZone, and FrameLayout) like a LinearLayout. 您正在将RelativeLayout(带有按钮,DeleteZone和FrameLayout的那个)视为LinearLayout。 For these three children, you need to specify where they are relative to each other or the parent. 对于这三个孩子,您需要指定它们相对于彼此或父对象的相对位置。 Parameters like layout_weight
and layout_gravity
are meaningless to a View that is the child of a RelativeLayout. 诸如layout_weight
和layout_gravity
类的参数对于作为RelativeLayout的子级的View而言毫无意义。 By default, they will all be jammed in the upper left corner of the RelativeLayout, since you are not specifying where they go. 默认情况下,它们都将卡在RelativeLayout的左上角,因为您没有指定它们的位置。
Personally, I would remove both LinearLayouts, both RelativeLayouts, and the FrameLayout, and use a single RelativeLayout for all of the children. 就个人而言,我将同时删除LinearLines,RelativeLayouts和FrameLayout,并为所有子代使用一个RelativeLayout。 That would be much cleaner. 那会干净得多。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.