Android布局的最佳实践

时间:2016-07-15 18:34:23

标签: android

Layout that I made

嗨我对android很新(大约2周)并阅读有关布局和属性的内容

但是以熟练程序员所熟知的最佳方式实现它会让人感到困惑,并且无法自行解决。

我做了布局,但我认为它没有很好地实现视图。

在附加的Image i上,我使用了多个LinearLayout深度

看起来像这样。使用LinearLayout和layout_weight

Layout I made

最好使用<relativeLayout><TableView>

我想有效地实施这些事情。

安全使用&#34; XX dp&#34;确保不同屏幕之间的相同外观?

额外问题1)    我在实施时遇到的问题。   多个&#34; match_parent&#34;,例如

如果我有类似

的话

<LinearLayout orientation="horizontal"> <TextView width="match_parent"> <TextView width="match_parent"> </LinearLayout>

它的行为类似于framelayout,因此只显示一个textView。

我想要的是具有静态表的视图,其具有三个固定容器,比例为1:3:1

   1      3       1
 |_ _ |_ _ _ _ |_ _ |

如何做到这一点?我如何使用&#34; layout_weight&#34;同 &#34; layout_width&#34;属性?我是否必须使用&#34; wrap_content&#34;?为什么? 可以用TableView吗?

完成

提前谢谢

1 个答案:

答案 0 :(得分:0)

检查此示例以使用重量,当使用重量时,您的宽度必须为0dp:

 <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:weightSum="5">

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="1" />

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="3"
        android:text="2" />

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="3" />

    </LinearLayout>
相关问题