2011-07-15 9 views
1

私はRelativeLayoutを使用しています。オレンジバーを中央の下に中央に置き、幅の90%を埋めたいとします。 LinearLayoutをパーセンテージで使用することは可能ですが、RelativeLayoutを使用するにはどうすればよいですか?Android:RelativeLayoutのビューの幅のパーセンテージを設定する

私はプログラムでどのようにワイド(dp)の画面を計算し、これをオレンジ色のビューの幅として90%に設定する必要がありますか?

簡潔に言えば、オレンジバーは、RelativeLayoutを使用して中央の中央に90%の画面を持ち、xとyの座標をハードコーディングせずに、すべての画面密度で機能するようにしたいと思います。 (エッジで暗いバーは電話のエッジです)

enter image description here

答えて

1

ただの推測ではなく、試してみる価値:) 以下のようなあなたのレイアウト構造を再設計してください:

<LinearLayout[with 90% width]> 
    <RelativeLayout 
      android:layout_width="fill_parent" 
      ... 
     <!--this will fill up its parent i.e above LinearLayout which is 90% of the screen width --> 
    > 
      <!--child views goes here.. --> 
    </RelativeLayout> 
</LinearLayout> 
+0

実際に、これは私が探していたものでした。私は初心者です! –

0

compile 'com.android.support:percent:24.0.0' 

以下を参照してください新しいパーセントサポートライブラリを使用します例

<android.support.percent.PercentRelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <ImageView 
     app:layout_widthPercent="50%" 
     app:layout_heightPercent="50%" 
     app:layout_marginTopPercent="25%" 
     app:layout_marginLeftPercent="25%"/> 
</android.support.percent.PercentRelativeLayout> 

*詳細については* Tutorial1Tutorial2Tutorial3

関連する問題