Android XML 布局参数未按预期运行 [英] Android XML Layout Parameters Do Not Function As Expected
问题描述
我有 3 个问题:
- 图像视图(白色瓷砖的)看起来比 gridView 中的其他瓷砖大得多(这很奇怪,因为它仅设置为 5dp x 5dp)
- 在我的 editText、textView 和 imageView 上设置 android:layout_alignParentRight="true" 似乎不会将图像向右移动
- android:layout_below="@id/sqwhite" 似乎没有将我的 editText 放在我的 textView 下
(基本上:我需要在右下角正确调整这些大小,但我使用的参数似乎都没有任何效果.)
(Basically: I need to get these to be sized correctly in the bottom right hand corner but none of the parameters I've used seem to have any effect.)
有什么想法吗?
<?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="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:id="@+id/sqwhite"
android:layout_width="5dp"
android:layout_height="5dp"
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>
推荐答案
好的,我已经试过你的布局了,首先你不需要linearlayout中的xmlns
OK, I've tried your layout, and first of all, you don't need the xmlns in the linearlayout
关于其他:
1) 我猜 sqwhite 是白色的大瓷砖.如果是,我看不到任何 src 或背景,但是如果您使用 src,则使用它可能会拉伸视图.
1) I'm guessing sqwhite is the big white tile. if it is, I don't see any src or background, but the use of src if you're using it might stretch the view.
2) 布局就像我复制的那样,确实将所有项目向右移动,不知道那里发生了什么.
2) The layout just as I copied it, does move all items to the right, don't really know what's happening there.
3) 我发现这也能正常工作.
3)I see this also working properly.
其他评论:
-不需要framelayout
-The framelayout is unnecessary
-您可以为 image_source_frame 使用简单的线性布局
-You can use a simple linearlayout for the image_source_frame
这就是我所做的.尽管我更改了对您项目的一些引用,以便我可以使用图形布局,但还是将它们改回来.这种布局似乎可以解决您在这里的所有 3 个问题.
Here's what I did. Though I changed a few references to your project so I could use the graphical layout, so change them back. This layout as it is seems to solve all your 3 problems here.
<?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="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="#FFFF0000"
android:gravity="center"
android:horizontalSpacing="2dip"
android:numColumns="3"
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="#FF00FF00" />
<LinearLayout
android:id="@+id/image_source_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:orientation="vertical"
android:gravity="right" >
<ImageView
android:id="@+id/sqwhite"
android:layout_width="5dp"
android:layout_height="5dp"
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_marginRight="5dp" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:text=""
android:textColor="@android:color/white" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
这篇关于Android XML 布局参数未按预期运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!