Fragment gets cut off in TabbedActivity

215 Views Asked by At

This is the preview in the designer.

enter image description here

But when I run the app on a device (Galaxy S4 with 5.0.1) the bottom part of the fragment gets cut off.

enter image description here

chat_fragment.xml

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

    <ListView
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:stackFromBottom="true"
        android:transcriptMode="alwaysScroll"
        android:layout_marginBottom="48dip"
        android:background="#1b184b"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="48dip"
        android:layout_alignParentBottom="true"
        android:padding="0dp"
        android:layout_margin="0dp"
        android:background="#753636"
        android:orientation="horizontal">

        <EditText
            android:layout_width="345dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:hint="Send a message"
            android:id="@+id/newmsg"
            />

        <ImageButton
            android:id="@+id/newmsgsend"
            android:src="@drawable/ic_send"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="center_vertical"
            android:scaleType="fitEnd"
            android:backgroundTintMode="multiply"
            android:backgroundTint="#400202" />
    </LinearLayout>
</RelativeLayout>

Is this because of something that I should handle from the layout of the fragment?

2

There are 2 best solutions below

1
Arslan Ashraf On

I changed youx xml code. Just little changes . Use this layout

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

<ListView
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:stackFromBottom="true"
    android:transcriptMode="alwaysScroll"
    android:background="#1b184b"
    android:layout_alignParentTop="true"
    android:layout_above="@+id/edit_linear_layout"
    />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="48dip"
    android:layout_alignParentBottom="true"
    android:padding="0dp"
    android:layout_margin="0dp"
    android:background="#753636"
    android:orientation="horizontal"
    android:id="@+id/edit_linear_layout"
    >

    <EditText
        android:layout_width="345dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:hint="Send a message"
        android:id="@+id/newmsg"
        />

    <ImageButton
        android:id="@+id/newmsgsend"
        android:src="@drawable/ic_send"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="center_vertical"
        android:scaleType="fitEnd"
        android:backgroundTintMode="multiply"
        android:backgroundTint="#400202" />
</LinearLayout>
</RelativeLayout>
0
Welkin On

You can add bottom margin to your bottom most item to resolve the "cut off" issue.

android:layout_marginBottom="50dp"

In your case, change your ImageButton to the following

<ImageButton
    android:id="@+id/newmsgsend"
    android:src="@drawable/ic_send"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="center_vertical"
    android:scaleType="fitEnd"
    android:backgroundTintMode="multiply"
    android:backgroundTint="#400202" 
    android:layout_marginBottom="50dp" />