簡體   English   中英

Android在linearlayouts上均等大小

[英]Android equal sizing on linearlayouts

好吧,我想要以下布局:

在此處輸入圖片說明

我嘗試過的是使用帶有權重的線性布局。 我真的不想在每個元素上添加硬編碼寬度以使其正確。 事實是,我只是無法讓大盒子與第1行的第二個盒子並排而已,我似乎不明白為什么。 我可以使用權重或類似方法僅通過XML來實現嗎?

到目前為止我的布局:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="55dp"
    android:layout_marginTop="15dp"
    android:orientation="horizontal"
    android:weightSum="4" >

    <TextView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:text="1" >
    </TextView>

    <TextView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_marginLeft="15dp"
        android:layout_weight="1"
        android:gravity="center"
        android:text="2" >
    </TextView>

    <TextView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_marginLeft="15dp"
        android:layout_weight="1"
        android:gravity="center"
        android:text="3" >
    </TextView>

    <TextView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_marginLeft="15dp"
        android:layout_weight="1"
        android:gravity="center"
        android:text="4" >
    </TextView>

</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="55dp"
    android:layout_marginTop="15dp"
    android:orientation="horizontal"
    android:weightSum="4" >

    <Button
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:text="5" />

    <Button
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_marginLeft="15dp"
        android:layout_weight="3"
        android:text="Box x3 incl. margins" />

</LinearLayout>

可能有可能實現LinearLayouts,但是...使用權重,嵌套的LinearLayouts非常昂貴。 今天,我已經在真正復雜的布局上進行了優化,在不更改外觀的情況下,只需14s即可在高級設備上進行渲染-少於1s。

您正在尋找的可能是TableLayout。 解決方案在這里: http : //www.mkyong.com/android/android-tablelayout-example/

Try this...

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relative"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp" >

<TableRow
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <Button
        android:layout_weight="1"
        android:text="button1" />

    <Button
        android:layout_weight="1"
        android:text="button2" />

    <Button
        android:layout_weight="1"
        android:text="button3" />

    <Button
        android:layout_weight="1"
        android:text="button4" />
</TableRow>

<TableRow
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <Button android:text="button5" />

    <Button
        android:layout_span="3"
        android:text="button6" />
</TableRow>

</TableLayout>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM