Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
153 views
in Technique[技术] by (71.8m points)

Android XML Layout Parameters Do Not Function As Expected

enter image description here

I have 3 issues:

  1. The imageView (of a white tile) appears MUCH larger than the other tiles in the gridView (which is strange because it's only set to 5dp x 5dp)
  2. setting android:layout_alignParentRight="true" on my editText, textView and imageView do not seem to move the image to the right
  3. android:layout_below="@id/sqwhite" does not seem to place my editText under my 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.)

Any ideas?

<?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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

OK, I've tried your layout, and first of all, you don't need the xmlns in the linearlayout

about the rest:

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) The layout just as I copied it, does move all items to the right, don't really know what's happening there.

3)I see this also working properly.

Other comments:

-The framelayout is unnecessary

-You can use a simple linearlayout for the image_source_frame

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...