[英]android:layout_alignParentRight=“true” does nothing
I have an ImageView
which I've set to android:layout_alignParentRight="true"
however it does not appear on the right side of the screen and I'm not sure why (it is the white square appearing centered horizontally in the screenshot below). 我有一个ImageView
,我将其设置为android:layout_alignParentRight="true"
但是它没有出现在屏幕的右侧,我不确定为什么(它是白色正方形,在下面的屏幕截图中居中显示) 。
I understand this can only be used with a RelativeLayout
- but I've used one - so I'm not sure exactly why this is happening. 我知道这只能与RelativeLayout
一起使用-但我已经使用了一个-所以我不确定为什么会这样。
<?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="200dp"
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:src="@drawable/delete_zone" />
<FrameLayout
android:id="@+id/image_source_frame"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:layout_weight="0.5" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_gravity="right"
android:layout_marginRight="5dp"
android:layout_weight="1" >
<ImageView
android:id="@+id/sqwhite"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentRight="true"
android:layout_gravity="right"
android:layout_marginRight="5dp"
android:layout_weight="1" />
<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>
The one glaring thing that jumps out at me is the redefinition of the xmlns, which any compiler doesn't like and may prevent proper generation of the layout. 让我惊讶的一件事是xmlns的重新定义,这是任何编译器都不喜欢的,可能会妨碍布局的正确生成。 When I removed that and some of your dead code and tried running this, the "sqwhite" appeared on the right side. 当我删除该代码以及一些无效代码并尝试运行此代码时,“ sqwhite”出现在右侧。 See if fixing these items helps: 看看解决这些问题是否有帮助:
LinearLayout
redefines the XML Namespace, which is an error. 您的第一个LinearLayout
重新定义XML命名空间,这是一个错误。 This could be what's preventing the XML from compiling properly. 这可能是阻止XML正确编译的原因。 Other minor items: 其他次要项目:
layout_weight
only applies to children of LinearLayout
s, so having them in other ViewGroups is unnecessary. layout_weight
仅适用于LinearLayout
的子级,因此不需要将它们包含在其他ViewGroup中。 Remove them from image_source_frame
and its children 从image_source_frame
及其子项中删除它们 bottom_part
use layout_centerHorizontal
in a vertical LinearLayout
is redundant and should also be removed. 在垂直的LinearLayout
使用bottom_part
使用layout_centerHorizontal
是多余的,也应删除。 layout_alignParentRight
in your RelativeLayout
is useless, since only children of RelativeLayout
s can use it. 有layout_alignParentRight
在你RelativeLayout
是没用的,因为只有孩子RelativeLayout
S能够使用它。 Please remove. 请删除。 android:src
attribute to the ImageView
. 您没有为ImageView
设置android:src
属性。 So is it possible that the actual sqwhite is in the right place, and that that white square represents something else? 那么,实际的sqwhite是否在正确的位置,而该白色正方形代表其他内容呢? EDIT: I've re-pasted your code here, with the items I listed removed. 编辑:我在这里重新粘贴了您的代码,删除了我列出的项目。 Maybe this will help: 也许这会有所帮助:
<?xml version="1.0" encoding="utf-8"?>
<com.example.project.DragLayer xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drag_layer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/black" >
<LinearLayout
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="200dp"
android:layout_weight="0.2"
android:background="@android:color/black"
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:src="@drawable/delete_zone" />
<FrameLayout
android:id="@+id/image_source_frame"
android:layout_width="fill_parent"
android:layout_height="80dp" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="right"
android:layout_marginRight="5dp" >
<ImageView
android:id="@+id/sqwhite"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentRight="true"
android:layout_gravity="right"
android:layout_marginRight="5dp"
android:src="@android:drawable/ic_delete" /> <!-- for testing -->
<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" />
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.