2016-07-10 3 views
2

Как установить высоту изображения в формате xml-файла макета, чтобы быть 3/4-го его родительской высоты макета, полной ширины и видеообзора, чтобы занять остальное?set imageView height должно быть 3/4th его родителя

Ниже мой макет 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" 
     /> 

ответ

2

Вы можете использовать weight для достижения этого.

Установить родительский быть LinearLayout и добавить

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

к родителю и

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

к ребенку, который вы хотите сделать 3/4. Для другого ребенка, добавьте

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

Таким образом, ваш код должен выглядеть следующим образом:

<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

Использование LinearLayout и установить вес.

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