Android的layout_width和放大器; layout_height,它是如何工作的? [英] Android layout_width & layout_height, how it works?

查看:148
本文介绍了Android的layout_width和放大器; layout_height,它是如何工作的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个接口,其中两个或多个按钮,将显示给用户,如果单​​击一个按钮,一些布局将显示给他。我现在用的是 SlidingDrawer 用于这一目的。

嗯,我对 layout_width和放大器相混淆; layout_height性能

如果我设置如下图所示的属性只有处理1显示在屏幕上。

 机器人:layout_width =FILL_PARENT机器人:layout_height =WRAP_CONTENT
 

老实说说,我没有关于这两个属性足够的知识。 有人可以分享他的知识呢?

main.xml中:

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=垂直机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT>

    < SlidingDrawer机器人:ID =@ + ID / slidingDrawer1
            机器人:layout_width =FILL_PARENT机器人:layout_height =WRAP_CONTENT
            机器人:手柄=@ + ID /句柄1
            机器人:CONTENT =@ + ID /内容1>
                <按钮的android:文本=处理1的Andr​​oid版本:layout_height =WRAP_CONTENT
                        机器人:layout_width =FILL_PARENT机器人:ID =@ + ID /句柄1>< /按钮>
                <的LinearLayout机器人:ID =@ + ID /内容1
                        机器人:layout_width =FILL_PARENT机器人:layout_height =WRAP_CONTENT
                        机器人:方向=垂直安卓重力=中心
                        机器人:后台=#FF444444>
                        <按钮的android:文本=处理1第1项机器人:layout_height =WRAP_CONTENT
                                机器人:layout_width =WRAP_CONTENT机器人:ID =@ + ID / ITEM1>< /按钮>
                < / LinearLayout中>
    < / SlidingDrawer>

    < SlidingDrawer机器人:ID =@ + ID / slidingDrawer2
            机器人:layout_width =FILL_PARENT机器人:layout_height =WRAP_CONTENT
            机器人:手柄=@ + ID / handle2
            机器人:CONTENT =@ + ID /内容2>
                <按钮的android:文本=处理2的Andr​​oid版本:layout_height =WRAP_CONTENT
                        机器人:layout_width =FILL_PARENT机器人:ID =@ + ID / handle2>< /按钮>
                <的LinearLayout机器人:ID =@ + ID /内容2
                        机器人:layout_width =FILL_PARENT机器人:layout_height =WRAP_CONTENT
                        机器人:方向=垂直安卓重力=中心
                        机器人:后台=#FF444444>
                        <按钮的android:文本=处理2第1项机器人:layout_height =WRAP_CONTENT
                                机器人:layout_width =WRAP_CONTENT机器人:ID =@ + ID / ITEM2>< /按钮>
                < / LinearLayout中>
    < / SlidingDrawer>
< / LinearLayout中>
 

<=h2_linDIV class>的解决方案

layout_width layout_height 属性的视图意图被使用其父容器。一些容器忽略的一个或两个的这些;最尊敬他们。您需要咨询的容器的文件(在你的情况,SlidingDrawer),以了解该值将被使用。

您不显示完整的main.xml,所以很难说究竟发生了什么错误。这也将有助于如果你贴的什么是错的图像。

修改

看到你完成布局后,我觉得这里的基本问题是,你正在使用的LinearLayout遏制SlidingDrawers。由于文档的SlidingDrawer 的注意,他们需要在任何一个的FrameLayout或一个RelativeLayout的(实际上,任何容器,它允许多个视图坐在彼此之上)。

另一种可能性是,所述第二SlidingDrawer被直接下的第1放置。试着改变第二个按钮的大小(如使文字更长时间),看看它是否戳了按钮1的两侧。

I am trying to create an interface, where two or more buttons will be displayed to the user, if a button is clicked, some Layouts will be displayed to him. I am using the SlidingDrawer for this purpose.

Well, i am confused by layout_width & layout_height properties.

If i set the properties like below only the "Handle 1" is shown on the screen.

android:layout_width="fill_parent" android:layout_height="wrap_content"

Honestly saying, i don't have enough knowledge about both of these properties. Can someone please share his knowledge about them?

main.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">

    <SlidingDrawer android:id="@+id/slidingDrawer1"
            android:layout_width="fill_parent" android:layout_height="wrap_content"
            android:handle="@+id/handle1"
            android:content="@+id/content1">
                <Button android:text="Handle 1" android:layout_height="wrap_content"
                        android:layout_width="fill_parent" android:id="@+id/handle1"></Button>
                <LinearLayout android:id="@+id/content1"
                        android:layout_width="fill_parent" android:layout_height="wrap_content"
                        android:orientation="vertical" android:gravity="center"
                        android:background="#FF444444">
                        <Button android:text="Handle 1 Item 1" android:layout_height="wrap_content"
                                android:layout_width="wrap_content" android:id="@+id/item1"></Button>
                </LinearLayout>
    </SlidingDrawer>

    <SlidingDrawer android:id="@+id/slidingDrawer2"
            android:layout_width="fill_parent" android:layout_height="wrap_content"
            android:handle="@+id/handle2"
            android:content="@+id/content2">
                <Button android:text="Handle 2" android:layout_height="wrap_content"
                        android:layout_width="fill_parent" android:id="@+id/handle2"></Button>
                <LinearLayout android:id="@+id/content2"
                        android:layout_width="fill_parent" android:layout_height="wrap_content"
                        android:orientation="vertical" android:gravity="center"
                        android:background="#FF444444">
                        <Button android:text="Handle 2 Item 1" android:layout_height="wrap_content"
                                android:layout_width="wrap_content" android:id="@+id/item2"></Button>
                </LinearLayout>
    </SlidingDrawer>     
</LinearLayout>

解决方案

The layout_width and layout_height properties of a view are intended to be used by its parent container. Some containers ignore one or both of these; most honor them. You need to consult the documentation of the container (in your case, SlidingDrawer) to understand how the values will be used.

You don't show the complete main.xml, so it's hard to say exactly what's going wrong. It would also help if you posted an image of what's wrong.

EDIT

After seeing your complete layout, I think that the basic problem here is that you are using a LinearLayout to contain the SlidingDrawers. As the docs for SlidingDrawer note, they need to be in either a FrameLayout or a RelativeLayout (actually, any container that allows multiple views to sit on top of one another).

Another possibility is that the second SlidingDrawer is being placed directly under the first one. Try changing the size of the second button (e.g., make the text longer) and see if it pokes out on either side of button 1.

这篇关于Android的layout_width和放大器; layout_height,它是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆