2017-01-25 1 views
0

I ein Layout mit PercentRelativeLayout als Stammansicht habe:layout_aspectRatio auf 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> 

was ich tun muß, um ein 16 festgelegt ist: 9-Seitenverhältnis auf die PercentRelativeLayout und dann 2 Bilder haben (jeweils 50% breites) in der, so sieht es etwa so aus:

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

Aber wenn ich die app laufen, die beiden Bilder nicht auftauchen (als ob die Ansicht nicht existiert).

Was soll ich ändern, um zu bekommen, was ich brauche?

+0

'App: layout_aspectRatio 'ist ein Attribut, das Sie auf die * Kinder * von' PercentRelativeLayout' anwenden, nicht auf das 'PercentRelativeLayout' selbst. – ianhanniballake

+0

@ianhanniballake Das würde Sinn machen. Gibt es ein Layout/eine Methode zum Anwenden eines Seitenverhältnisses auf eine Elternansicht (wie ein RelativeLayout) und müssen sich die Kinder darauf einstellen? –

+0

Sie können sicherlich ineinander verschachteln – ianhanniballake

Antwort

0

Wenn Sie PercentRelativeLayout verwenden, müssen Sie die Breite oder Höhe festlegen, damit die andere basierend auf dem Prozentsatz berechnet wird. Da stellen Sie die Wurzelhöhe als wrap_content Sie benötigen die Kinder Höhe wie wrap_content oder einen festen Wert zu setzen und ein optimales Ergebnis zu haben, es wäre eine gute Idee sein, eine Mindesthöhe einstellen

<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> 
Verwandte Themen