2017-01-25 3 views
0

にlayout_aspectRatio:Iは、ルートビューとして<a href="https://developer.android.com/reference/android/support/percent/PercentRelativeLayout.html" rel="nofollow noreferrer">PercentRelativeLayout</a>とレイアウトを有するPercentRelativeLayout

<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="wrap_content" 
    app:layout_aspectRatio="178%"> 

    <ImageView 
     android:id="@+id/firstImage" 
     app:layout_widthPercent="50%" 
     android:scaleType="centerCrop" 
     /> 

    <ImageView 
     android:id="@+id/secondImage" 
     app:layout_widthPercent="50%" 
     android:scaleType="centerCrop" 
     android:layout_toRightOf="@id/firstImage" 
     /> 

</android.support.percent.PercentRelativeLayout> 

Iが16に設定されている実行する必要がどのようなワイド2枚の画像を有する次いでPercentRelativeLayoutと上の9のアスペクト比を(それぞれ50% )内に、それは次のようになります。

http://i.imgur.com/Iy8JiCQ.png

しかし、私はアプリを実行したときにビューが存在しないかのように、2枚の画像が)(表示されません。

私は何が必要なのですか?

+0

を設定することが良いでしょう。layout_aspectRatio 'は、PercentRelativeLayout'自体ではなく、' PercentRelativeLayout'の* children *に適用する属性です。 – ianhanniballake

+0

@ianhanniballakeそれは理にかなっています。親ビュー(RelativeLayoutのような)にアスペクト比を適用し、それに従って子供たちに調整させるレイアウト/メソッドがありますか? –

+0

確かに別のものの中に入れ子にすることができます – ianhanniballake

答えて

0

PercentRelativeLayoutを使用する場合、幅または高さを設定して、パーセントがパーセントに基づいて計算されるようにする必要があります。 あなたはwrap_contentまたは固定値として子供の高さを設定して、最高の結果を持っている必要がありますwrap_contentとしてルートの高さを設定しているので、 `アプリ最小の高さ

<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="wrap_content" 
    app:layout_aspectRatio="178%"> 

<ImageView 
    android:id="@+id/firstImage" 
    app:layout_widthPercent="50%" 
    android:layout_height="wrap_content" 
    android:minHeight="100dp" 
    android:scaleType="centerCrop" /> 

<ImageView 
    android:id="@+id/secondImage" 
    app:layout_widthPercent="50%" 
    android:layout_height="wrap_content" 
    android:minHeight="100dp" 
    android:scaleType="centerCrop" 
    android:layout_toRightOf="@id/firstImage" /> 

</android.support.percent.PercentRelativeLayout> 
関連する問題

 関連する問題