2016-07-10 7 views
2

レイアウトxmlファイル内のimageViewの高さを、親のレイアウトの高さの全幅、全幅、ビデオビューの3/4に設定するにはどうすればいいですか?続きset imageViewの高さを親の3/4にする

は私のレイアウト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こと、あなたが3/4をしたい子供に

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

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

を追加する親を設定します。他の子に、

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> 
関連する問題