2015-07-11 189 views
1

我想在屏幕的橫向模式中將劃分的屏幕設計爲兩個不相等的部分。所以,我認爲自動使用片段。但是我遇到的問題是每個片段都與屏幕的一半相匹配。這不是我想要的。我想要的是兩部分寬度不相等的屏幕。我想是這樣的:如何設置每個片段的屏幕百分比

enter image description here

+0

發佈你試過的東西,直到 – koutuk

+0

權重被引入您的需要 – Eenvincible

回答

2

你可以利用重量參數。

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

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="3" /> 
</LinearLayout> 

請注意用於兩個LinearLayout的權重。第一個權重爲1(可以佔用屏幕的1/4),第二個權重爲3(可以佔用屏幕的3/4)。

只要使用這個完全相同的概念爲您的片段,並保持不變的比例,如你所願。

希望我能說清楚。

+0

謝謝Aritra – HiddenDroid

0

使用重量參數

<LinearLayout android:orientation="vertical" android:layout_height="fill_parent" android:layout_width="fill_parent"> 
    <LinearLayout android:layout_weight="1" android:layout_height="fill_parent" android:layout_width="fill_parent"/> 
    <LinearLayout android:layout_weight="3" android:layout_height="fill_parent" android:layout_width="fill_parent"/> 
</LinearLayout> 
+0

fill_parent已被棄用,因爲sdk 8.請使用match_parent – Eenvincible

0

組線性佈局重量實現這個...

<?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="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="2" /> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" /> 
</LinearLayout>