如何使布局是在屏幕的宽度的80%? [英] How to make layout to be 80% of the width of the screen?

查看:254
本文介绍了如何使布局是在屏幕的宽度的80%?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么可以做一些布局是,例如,80%或90%的屏幕宽度的,不管是什么是屏幕尺寸还是DPI?我试着用但我得到80%的高度的话。

How can I make some layout to be for example 80% or 90% of the width of the screen, no matter what is the screen size or DPI? I tried with " but I get 80% of the height then.

编辑:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/background" >

    <Button
        android:id="@+id/bNivoi1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="80dp"
        android:background="@drawable/button_nivoi_back" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:weightSum="1"
        android:orientation="horizontal" >

    <TextView
        android:id="@+id/tvOpis15Nivoa"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:gravity="center"
        android:textSize="15sp"
        android:layout_weight="0.8"
        android:text="text" />
    </LinearLayout>

</LinearLayout>

我只需要TextView的是在屏幕的80%,不活动的其余部分。

I only need textview to be 80% of the screen, not the rest of the activity.

推荐答案

的android:layout_weight 是根据安卓方向你的的LinearLayout 的 - 如果你希望你的布局占用宽度的80%,你需要一个的LinearLayout 的android:方向=横向

android:layout_weight is based on the android:orientation of your LinearLayout - if you want your layout to take up 80% of the width, you need a LinearLayout with an android:orientation="horizontal"

<LinearLayout
    android:id="@+id/your_outer_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" > <!-- note that vertical is the default -->

    <!-- Other elements here -->

    <LinearLayout
        android:id="@+id/eighty_percent_layout_holder
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="1">
        <View
            android:id="@+id/your_eighty_percent_layout"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.8" />
     </LinearLayout>

    <!-- Other elements here -->
</LinearLayout>

这篇关于如何使布局是在屏幕的宽度的80%?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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