机器人:layout_height屏幕大小的50% [英] android:layout_height 50% of the screen size

查看:203
本文介绍了机器人:layout_height屏幕大小的50%的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我刚刚实施了的LinearLayout里面一个ListView,但我需要定义的LinearLayout的高度(它是屏幕高度的50%)。

Hi all I just implemented a ListView inside a LinearLayout, but I need to define the height of the LinearLayout (it has to be 50% of the screen height).

<LinearLayout
    android:id="@+id/widget34"
    android:layout_width="300px"
    android:layout_height="235px"
    android:orientation="vertical"
    android:layout_below="@+id/tv_scanning_for"
    android:layout_centerHorizontal="true">

    <ListView
        android:id="@+id/lv_events"
        android:textSize="18sp"         
        android:cacheColorHint="#00000000"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tv_scanning_for"
        android:layout_centerHorizontal="true">
    </ListView>

</LinearLayout>

时的不可能性?

Is that possibile?

我也做了类似的一个按钮和一个EditText的东西,但似乎并没有工作布局。

I did something similar for a button and an EditText, but doesn't seem to work on Layouts.

这是我的code:

    //capture the size of the devices screen
    Display display = getWindowManager().getDefaultDisplay();
    double width = display.getWidth();

    //my EditText will be smaller than full screen (80%)        
    double doubleSize = (width/5)*4;
    int editTextSize = (int) doubleSize;

    //define the EditText 
    userName = (EditText) this.findViewById(R.id.userName);
    password = (EditText) this.findViewById(R.id.password);

    //set the size
    userName.setWidth(editTextSize);
    password.setWidth(editTextSize);

感谢您! :)

推荐答案

设置了 layout_height =0dp *,添加一个空白查看下方(或空白的ImageView 或只是的FrameLayout )使用 layout_height 也等于 0dp ,并设置两种观点有一个 layout_weight =1

Set its layout_height="0dp"*, add a blank View beneath it (or blank ImageView or just a FrameLayout) with a layout_height also equal to 0dp, and set both Views to have a layout_weight="1"

这会拉伸每个视图一样,因为它充满屏幕。因为两者都具有相同的重量,每个将在屏幕的50%。

This will stretch each View equally as it fills the screen. Since both have the same weight, each will take 50% of the screen.

*请参阅adamp的评论为什么,工程和其他真正有用的花絮。

*See adamp's comment for why that works and other really helpful tidbits.

这篇关于机器人:layout_height屏幕大小的50%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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