开发者

trouble with nested layouts

开发者 https://www.devze.com 2023-01-28 15:04 出处:网络
I\'m just beginning Android and have gotten myself stuck.I\'ve made a simple app/view.The idea is draw a line-maze in the top, with motion buttons on the bottom.My app only draws an x with a couple li

I'm just beginning Android and have gotten myself stuck. I've made a simple app/view. The idea is draw a line-maze in the top, with motion buttons on the bottom. My app only draws an x with a couple lines in the frame, but that works. The problem is that my buttons are being drawn too far down, and are clipped in height.

I assume the problem is all in my layout xml:

<?xml version="1.0" encoding="utf-8"?>开发者_运维技巧
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

        <FrameLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1" > 

            <none.maze.MazeView
             android:id="@+id/maze"
                android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        />

            <RelativeLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" >
                <TextView
                 android:id="@+id/text"
                    android:text="@string/maze_layout_text_text"
                    android:visibility="visible"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:gravity="center_horizontal"
                    android:textColor="#ff8888ff"
                    android:textSize="24sp"/>
            </RelativeLayout>

        </FrameLayout>

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1" >             

            <Button
                android:id="@+id/left"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Left" 
                android:layout_weight="1" 
                />

            <Button
                android:id="@+id/forward"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Forward" 
                android:layout_weight="1" 
                />

            <Button
                android:id="@+id/right"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Right" 
                android:layout_weight="1" 
                />

        </LinearLayout>

</LinearLayout>


I think you shouldn't use layout_height="fill_parent" and layout_weight at the same time. Try to set layout_height="0dip" and layout_weight="1" for the FrameLayout and layout_height="wrap_content" for the lower LinearLayout. The lower LinearLayout mustn't have the layout_weight attribute.


Use Hierarchy Viewer to debug your layout. Its pretty cool.


Your entire layout is just way too bloated and ineffective. You use way too many ViewGroups. I recommend reading about RelativeLayouts and especially the entire Layout Tricks series.

0

精彩评论

暂无评论...
验证码 换一张
取 消