0

I am creating a layout as below but the checkbox element is not visible on the scren where am i goign wrong ?

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

    <LinearLayout android:orientation="horizontal" 
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <SeekBar android:id="@+id/seek" 
            android:layout_width="300dip"
            android:layout_height="wrap_content" 
            android:progress="50"/>

        ...and a few more elements here.

    </LinearLayout>

    <CheckBox android:id="@+id/CheckBox" 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:text="somestring" />

</LinearLayout>
0

5 Answers 5

1

The LinearLayout before the CheckBox has its height set to MATCH_PARENT(and it fills all the parent's height) and the parent LinearLayout of both has the orientation set to vertical so the CheckBox is pushed out of the screen.

Set the height of the LinearLayout containing the SeekBar to WRAP_CONTENT for example.

0

You need to set your inner Linear Layout's height and width to wrap content. Try this.

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

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <SeekBar
            android:id="@+id/seek"
            android:layout_width="300dip"
            android:layout_height="wrap_content"
            android:progress="50" />
    </LinearLayout>

    <CheckBox
        android:id="@+id/CheckBox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="somestring" />

</LinearLayout>
0

Try This :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="10" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="9"
    android:orientation="horizontal" >

    <SeekBar
        android:id="@+id/seek"
        android:layout_width="300dip"
        android:layout_height="wrap_content"
        android:progress="50" />
</LinearLayout>

<CheckBox
    android:id="@+id/CheckBox"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:text="somestring" />

</LinearLayout>
0

In your layout chose one element that you want to be flexible in size, say height wise. Then make its height="0dp" and weight="1". Make heights of rest of elements: height="wrap_content".

Also you may have given discreet size of some dp to your other elements, and hence their total height runs out of available screen space OR there are too many elements that they go beyond your screen height. In this case, wrap your layout in a ScrollView.

0

change your LinerLayout definition it cannot be android:layout_height="match_parent"

<LinearLayout android:orientation="horizontal" 
    android:layout_width="match_parent"
    android:layout_height="0px"
    android:layout_weight="1">

if you set match_parent for linearlayout it consumes all content so wrap_content is better. But if you set it as I wrote checkbox will be at bottom page a linearlayout will consumes remaing part of screen.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.