Reputation: 3840
I am having a linearlayout and scrollbar. I am trying to have button below the scrollbar. Can you please suggest what I am doing wrong here.
Here is my XML code :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView
android:id="@+id/scroll1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TableLayout
android:id="@+id/table_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</TableLayout>
</ScrollView>
<Button android:id="@+id/next_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Next"
android:textColor="@android:color/background_light"
/>
</LinearLayout>
Thanks,
Aman
Upvotes: 0
Views: 85
Reputation: 352
You should use Relative layout in place of LinearLayout. That will solve some problem
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/next_btn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Next"
android:layout_alignParentBottom="true"
android:textColor="@android:color/background_light"
/>
<ScrollView
android:id="@+id/scroll1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@id/next_btn" >
<TableLayout
android:id="@+id/table_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</TableLayout>
</ScrollView>
</RelativeLayout>
Upvotes: 0
Reputation: 8153
By setting ScrollView
weight to 1 and height to 0dp it will wrap its height to fill all the space left after the Button
gets layouted to use wrap_content height:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView
android:id="@+id/scroll1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<TableLayout
android:id="@+id/table_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</TableLayout>
</ScrollView>
<Button
android:id="@+id/next_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Next"
android:textColor="@android:color/background_light" />
</LinearLayout>
Upvotes: 1
Reputation: 8849
add
layout_weight
parameter to each part( i added 90% scrollview 10% button)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView
android:id="@+id/scroll1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="9" >
<TableLayout
android:id="@+id/table_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</TableLayout>
</ScrollView>
<Button android:id="@+id/next_btn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Next"
android:textColor="@android:color/background_light"
android:layout_weight="1"
/>
</LinearLayout>
Upvotes: 0