1
votes

I am trying to get my controls so that I display a control that has a button and an image that takes up the remaining space. I have been looking at using weights I can get it to work on the width but as soon as I use the weight on height nothing is displayed, my code is as follows:

<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" >
    <LinearLayout android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:baselineAligned="true" android:weightSum="100">

        <com.example.test.MyImageView
            android:id="@+id/test_img" 
            android:layout_height="0dp"         
            android:layout_width="wrap_content"
            android:layout_weight="75"
            android:scaleType="fitCenter"       
             />

       <Button
        android:id="@+id/RedrawBtn"
        android:layout_height="0dp"     
        android:layout_width="wrap_content"     
        android:layout_weight="25"
        android:text="Button" /> 
    </LinearLayout>
</RelativeLayout>
3
Please see my answer, it will solve your problem.Dipak Keshariya

3 Answers

2
votes

you haven't given orientation to LinearLayout

<LinearLayout android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:baselineAligned="true" android:weightSum="100"
    android:orientation="vertical">

    <com.example.test.MyImageView
        android:id="@+id/test_img" 
        android:layout_height="0dp"         
        android:layout_width="wrap_content"
        android:layout_weight="75"
        android:scaleType="fitCenter"       
         />

   <Button
    android:id="@+id/RedrawBtn"
    android:layout_height="0dp"     
    android:layout_width="wrap_content"     
    android:layout_weight="25"
    android:text="Button" /> 
</LinearLayout>
2
votes

try this code

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

    <LinearLayout android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:baselineAligned="true"
    android:orientation="vertical">

        <com.example.test.MyImageView
            android:id="@+id/test_img" 
            android:layout_height="0dp"         
            android:layout_width="wrap_content"
            android:layout_weight="1"
            android:scaleType="fitCenter"       
             />

       <Button
        android:id="@+id/RedrawBtn"
        android:layout_height="wrap_content"     
        android:layout_width="wrap_content"     
        android:text="Button" /> 
    </LinearLayout>
</RelativeLayout>
0
votes

Write below code instead of your code, it will solve your problem.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <com.example.test.MyImageView
        android:id="@+id/test_img" 
        android:layout_height="match_parent"         
        android:layout_width="wrap_content"
        android:layout_weight="75"
        android:scaleType="fitCenter" />

    <Button
        android:id="@+id/RedrawBtn"
        android:layout_height="match_parent"     
        android:layout_width="wrap_content"     
        android:layout_weight="25"
        android:text="Button" /> 

</LinearLayout>