2016-07-10 8 views
2

Wie setze ich die Höhe von imageView innerhalb der Layout xml Datei auf 3/4 der übergeordneten Layouthöhe, voller Breite und videoView um den Rest zu belegen?set imageView height auf 3/4 seiner Eltern

Folgende ist mein Layout xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="app.com.blynq.player.MainActivity"> 


    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/imageView" 
     android:layout_centerVertical="true" 
     android:layout_centerHorizontal="true" 
     android:adjustViewBounds="true" 
     /> 

    <VideoView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/videoView" 
     android:layout_gravity="center" 
     android:adjustViewBounds="true" 
     /> 

Antwort

2

Sie können weight verwenden, dies zu erreichen.

Set die Eltern ein LinearLayout zu sein und

android:orientation="vertical" 
android:weightSum="4" 

an die Eltern und

android:layout_height="0dp" 
android:layout_width="match_parent" 
android:layout_weight="3" 

dem Kind hinzufügen Sie möchten 3/4 machen. Zum anderen Kind, fügen

android:layout_height="0dp" 
android:layout_width="match_parent" 
android:layout_weight="1" 

Daher sollten Sie den Code wie folgt aussehen:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:weightSum="4" 
    tools:context="app.com.blynq.player.MainActivity"> 

    <ImageView 
     android:layout_height="0dp" 
     android:layout_width="match_parent" 
     android:layout_weight="3" 
     android:id="@+id/imageView" 
     android:layout_centerVertical="true" 
     android:layout_centerHorizontal="true" 
     android:adjustViewBounds="true"/> 

    <VideoView 
     android:layout_height="0dp" 
     android:layout_width="match_parent" 
     android:layout_weight="1" 
     android:id="@+id/videoView" 
     android:layout_gravity="center" 
     android:adjustViewBounds="true"/> 
</LinearLayout> 
0

Verwenden Linearlayout und Gewicht eingestellt.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="app.com.blynq.player.MainActivity"> 


    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/imageView" 
     android:weight="3" 
     android:layout_centerVertical="true" 
     android:layout_centerHorizontal="true" 
     android:adjustViewBounds="true" 
     /> 

    <VideoView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/videoView" 
     android:weight="1" 
     android:layout_gravity="center" 
     android:adjustViewBounds="true" 
     /> 
</LinearLayout>