2015-05-10 40 views
-5

這是我想我的佈局:Android的發展規劃

http://i.imgur.com/1iAtjCw.png

我想2爲1的高度的90%。 3應該是1的10%。

我試過讓1是一個LinearLayout,FrameLayout,RelativeLayout,但我無法讓它工作。我在想我只是想念一些簡單的東西。

編輯(添加執行):

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_weight="80" 
    android:layout_marginLeft="15dp" 
    android:layout_marginRight="15dp" 
    android:layout_marginTop="-1dp" 
    android:orientation="vertical" 
    android:weightSum="100" 
> 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="80" 
     android:background="@drawable/bg_black_opaque"> 
    </LinearLayout> 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="20" 
     android:layout_marginTop="-30dp"> 
    </LinearLayout> 
</LinearLayout> 
+0

您使用的WebView考慮? –

+0

我還沒有,我是新來的。我會研究並回復。 編輯:我沒有看到這將如何解決我的問題。 – tyejae

+0

顯示您的實施 – silverFoxA

回答

0

試試這個

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@color/background"> 
<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_marginBottom="10dp" 
    android:layout_marginTop="5dp" 
    android:background="@color/black" 
    android:layout_marginRight="5dp" 
    android:layout_marginLeft="10dp" 
    android:layout_height="match_parent"> 
    <RelativeLayout 
     android:layout_alignParentBottom="true" 
     android:layout_width="match_parent" 
     android:background="@color/cost" 
     android:layout_height="60sp"/> 
</RelativeLayout> 

+0

感謝@Virus,這正是我一直在尋找的。 – tyejae

+0

很高興幫助.. – silverFoxA

0

試試這個

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_content"> 

    <RelativeLayout 
     android:id="@+id/view2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 

    <RelativeLayout 
     android:id="@+id/view3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 

</RelativeLayout> 

現在在Java代碼中獲取設備分辨率的高度

DisplayMetrics metrics = new DisplayMetrics(); 
getWindowManager().getDefaultDisplay().getMetrics(metrics); 
int deviceHeight = metrics.heightPixels; 

,並設置你的LayoutParams您的視圖2和view3以編程方式。

RelativeLayout.LayoutParams paramsView3 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,0.9 * deviceHeight); 
paramsView3 .addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); 
view3.setLayoutParams(paramsView3); 

RelativeLayout.LayoutParams paramsView2 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, 0.2 * deviceHeight); 
view2.setLayoutParams(paramsView2); 
+0

這不幸的是不允許它們重疊。我希望它們像圖像顯示一樣重疊。 – tyejae

+0

你想要它嗎?我的意思是你想view3重疊確切的一半? – Kunu

+0

我想view3重疊view2的view3的高度的一半。 – tyejae