Hbk Hhh
Hbk Hhh

Reputation: 73

android can't display the bottom of the layout

I made an android app that contain scrollview layout and inside it AbsoluteLayout, the problem is I can't display the bottom of the layout it only display the top of the layout. I tried to use layout_marginBottom in the AbsoluteLayout but it didn't work.

Upvotes: 0

Views: 117

Answers (4)

Ranjit
Ranjit

Reputation: 5150

Use RelativeLayout instead of AbsoluteLayout. Also don't scroll the total layout. Just scroll the View only.

Check it once:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:layout_marginTop="40dp"
android:background="@drawable/bg"  >

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="300dp" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:text="TextView" />

</ScrollView>

<Button
    android:id="@+id/btn1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:text="Button" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/btn1"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="27dp"
    android:text="@string/s3"
    android:textSize="16sp"
    android:text="TextView" />

</RelativeLayout>

Upvotes: 2

Akash Jindal
Akash Jindal

Reputation: 505

use property android:fillViewPort=true inside ScrollView as follows

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:fillViewport="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg"
android:orientation="vertical" >

Upvotes: 0

diptia
diptia

Reputation: 2245

True , absolute layout is deprecated . Also , here is a tip :

When creating an xml layout for Android , the easiest way to check for error is using the "graphical layout" tab of the xml layout file . Graphical layout editor . Use an appropriate device configuration ( match your device ) and the API version , reproduce that error and see if changing the layout parameters help .

Upvotes: 0

Maveňツ
Maveňツ

Reputation: 1

Use RelativeLayout and set left and right margins like

RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
lp.leftMargin = x;
lp.topMargin =  y;

Upvotes: 0

Related Questions