![](/img/trans.png)
[英]How to control what happens when a view's wrap_content exceeds its parent's width/height?
[英]View half of its parent's height and width
如何將android視圖設置為其父級寬度和高度的一半? 像這里的主演部分:
+-------|-------+
|*******| |
|*******| |
|*******| |
|*******| |
|*******| |
|*******| |
|-------|-------|
| | |
| | |
| | |
| | |
| | |
| | |
+-------|-------+
編輯
任何人閱讀這個問題,你最好使用程序兼容性GridLayout
,並使用column_weight
作為解釋這里嵌套的權重是昂貴的。
一些假布局和布局重量必須做的伎倆..
<?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:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#FFFFFF"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="@+id/dummy"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:visibility="invisible" >
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<LinearLayout
android:id="@+id/dummy"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:visibility="invisible" >
</LinearLayout>
<LinearLayout
android:id="@+id/dummy"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:visibility="invisible" >
</LinearLayout>
</LinearLayout>
</LinearLayout>
有多種方法可以這樣做 - 取決於上下文 - 但一種方法是使用layout_weight
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.