0

外側の2つのビューが固定幅で、中間のビューが残りの利用可能な水平スペースを満たすように、3つのビューを水平にレイアウトするにはどうすればよいですか?これを実行しようとする私の試みはすべて、一番右のビューが画面から押し出される結果となりました。Androidレイアウト:2つの固定幅ビュー間の可変幅ビュー

答えて

0

私はしばらくの間、この作業を得るために苦労し、RelativeLayoutでどうやってそれを行うのかを見つけました。次のコード例を参照してlayout_toRightOflayout_toLeftOfの使用に細心の注意を払う、とlayout_alignParentRight

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="@dimen/eventDetailSectionHeight" 
    android:background="@color/grayout"> 

    <SomeFixedWidthView 
     android:id="@+id/leftFixedWidthView" 
     android:layout_width="100dp" 
     android:layout_height="match_parent"/> 

    <SomeVariableWidthView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_toRightOf="@id/leftFixedWidthView" 
     android:layout_toLeftOf="@+id/rightFixedWidthView"/> 

    <SomeFixedWidthView 
     android:id="@+id/rightFixedWidthView" 
     android:layout_width="100dp" 
     android:layout_height="match_parent" 
     android:layout_alignParentRight="true"/> 

</RelativeLayout> 
0

は、要件に応じて、それぞれの子のためにlayout_weightを設定してみてください。ご希望の結果のためのコードの下

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:weightSum="1"> 


     <View 
      android:id="@+id/leftView" 
      android:layout_width="0dp" 
      android:layout_weight="0.4" 
      android:layout_height="match_parent" 
      android:background="#ff0000"/> 

     <View 
      android:id="@+id/middleView" 
      android:layout_width="0dp" 
      android:layout_weight="0.2" 
      android:layout_height="match_parent" 
      android:background="#33cc33"/> 

     <View 
      android:id="@+id/rightView" 
      android:layout_width="0dp" 
      android:layout_weight="0.4" 
      android:layout_height="match_parent" 
      android:background="#ff0000"/>/> 


</LinearLayout> 
0

使用

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <View 
     android:id="@+id/leftView" 
     android:layout_width="100dp" 
     android:layout_height="match_parent" 
     android:background="#ff0000"/> 

    <View 
     android:id="@+id/middleView" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="#33cc33"/> 

    <View 
     android:id="@+id/rightView" 
     android:layout_width="100dp" 
     android:layout_height="match_parent" 
     android:background="#ff0000"/> 

</LinearLayout> 
関連する問題