Android测量屏幕的百分比

时间:2015-04-25 05:34:44

标签: android xml android-layout

我做了很多关于Android布局的研究我找到了很多答案,但没有找到任何答案告诉我如何以实际百分比衡量屏幕 刚发现表格布局线性与重量,最好的一个线性与重量,但很难再次管理百分比!

1 个答案:

答案 0 :(得分:4)

百分比表示比率超过100

具有重量的线性布局并不难以管理您可以在技术上以百分比形式管理线性布局,

假设你的主要布局是android:weightSum =“100” 这意味着您的总屏幕尺寸为100%,现在您可以指定每个布局宽度

示例

<?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" >

    <LinearLayout
        android:id="@+id/layout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="100" >

        <TextView
            android:id="@+id/one"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="12"
            android:background="#FF9933"
            android:text="No:" />

        <TextView
            android:id="@+id/two"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="63"
            android:background="#CC33CC"
            android:text="Desc" />

        <TextView
            android:id="@+id/three"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="25"
            android:background="#FF9999"
            android:text="Total" />
    </LinearLayout>

</LinearLayout>

根据百分比第一列是12%秒是63%而最后一列是25%