0

I've been making a tabbed activity with a list view in it. I've been trying to put a button under the list view, but when i run on my phone, the button doesn't show up.

My Fragment layout

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.siscaproject.sisca.Fragment.RegisterFragment">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="7dp">

        <RelativeLayout
            android:id="@+id/rl_total_data"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorRedPrimary"
            android:padding="8dp">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:text="@string/item_detected"
                android:textColor="#fff" />

            <TextView
                android:id="@+id/tv_total_data"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_marginEnd="7dp"
                android:hint="10 items detected"
                android:textColor="#fff" />
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/rl_data"
            android:layout_below="@id/rl_total_data"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ListView
                android:id="@+id/lv_data"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignParentStart="true"
                android:layout_alignParentTop="true" />

        </RelativeLayout>

        <Button
            android:id="@+id/btn_register"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentStart="true"
            android:background="@color/colorRedPrimary"
            android:text="@string/register_all_item"
            android:textAllCaps="false"
            android:textColor="#fff" />

    </RelativeLayout>

</FrameLayout>

My layout preview in my android studio

The Layout preview in my android studio

The layout when i run it on my phone (I'm using an Asus Zenfone 5)

When i run it on my phone

I'm not sure where i did wrong, i actually have change the button into the floating button, but only half of the button shows in the layout. (Plus i can't scroll the layout)

Update I have resolved it, the problem is in the tabbed activity layout. I use a constraint layout as the parent, i've changed it to Relative layout and it works perfectly

cleanrun
  • 549
  • 6
  • 20

5 Answers5

1

Try this code..

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.siscaproject.sisca.Fragment.RegisterFragment">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="7dp">

    <RelativeLayout
        android:id="@+id/rl_total_data"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorRedPrimary"
        android:padding="8dp">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:text="@string/item_detected"
            android:textColor="#fff" />

        <TextView
            android:id="@+id/tv_total_data"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_marginEnd="7dp"
            android:hint="10 items detected"
            android:textColor="#fff" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/rl_data"
        android:layout_below="@id/rl_total_data"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ListView
            android:id="@+id/lv_data"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:layout_above="@+id/btn_register" />

        <Button
            android:id="@+id/btn_register"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentStart="true"
            android:background="@color/colorAccent"
            android:text="submit"
            android:textAllCaps="false"
            android:textColor="#fff" />

    </RelativeLayout>


</RelativeLayout>

1

Try this

change color according to you!

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
   >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="7dp">

        <RelativeLayout
            android:id="@+id/rl_total_data"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorAccent"
            android:padding="8dp">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:text="detected"
                android:textColor="#fff" />

            <TextView
                android:id="@+id/tv_total_data"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_marginEnd="7dp"
                android:hint="10 items detected"
                android:textColor="#fff"
                android:layout_marginRight="7dp" />
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/rl_data"
            android:layout_below="@id/rl_total_data"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ListView
                android:id="@+id/lv_data"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignParentStart="true"
                android:layout_alignParentTop="true"
                android:layout_alignParentLeft="true" />

        </RelativeLayout>

        <Button
            android:id="@+id/btn_register"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentStart="true"
            android:background="@color/colorPrimary"
            android:text="helo"
            android:textAllCaps="false"
            android:textColor="#fff"
            android:layout_alignParentLeft="true" />

    </RelativeLayout>

</FrameLayout>
0

This is because of the "match parent" attribute that is in a view above your button.Your button therefore is not shown because a view on top of it has been set to occupy all the space of the parent.

SEE BELOW CODE modification

<FrameLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.siscaproject.sisca.Fragment.RegisterFragment">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="7dp">

        <RelativeLayout
            android:id="@+id/rl_total_data"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorRedPrimary"
            android:padding="8dp">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:text="@string/item_detected"
                android:textColor="#fff" />

            <TextView
                android:id="@+id/tv_total_data"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_marginEnd="7dp"
                android:hint="10 items detected"
                android:textColor="#fff" />
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/rl_data"
            android:layout_below="@id/rl_total_data"
            android:layout_width="match_parent"
           android:layout_height="wrap_content">

            <ListView
                android:id="@+id/lv_data"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentStart="true"
                android:layout_alignParentTop="true" />

        </RelativeLayout>

        <Button
            android:id="@+id/btn_register"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentStart="true"
            android:background="@color/colorRedPrimary"
            android:text="@string/register_all_item"
            android:textAllCaps="false"
            android:textColor="#fff" />

    </RelativeLayout>

</FrameLayout>

You could try to use weightSum as explained in this post.What is android:weightSum in android, and how does it work? It give much more control in division of your parent layout

Mushirih
  • 451
  • 5
  • 13
0

Try with this code

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="7dp">

<RelativeLayout
    android:id="@+id/rl_total_data"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimary"
    android:padding="8dp">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:text="Items Detected"
        android:textColor="#fff" />

    <TextView
        android:id="@+id/tv_total_data"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_marginEnd="7dp"
        android:hint="10 items detected"
        android:textColor="#fff" />
</RelativeLayout>



    <ListView
        android:id="@+id/lv_data"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/btn_register"
        android:layout_below="@+id/rl_total_data"/>


<Button
    android:id="@+id/btn_register"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="@color/colorAccent"
    android:text="Register"
    android:textAllCaps="false"
    android:textColor="#fff" />

Vivek Mishra
  • 5,669
  • 9
  • 46
  • 84
0

Try this

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.siscaproject.sisca.Fragment.RegisterFragment">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="7dp"
    android:orientation="vertical">

    <RelativeLayout
        android:id="@+id/rl_total_data"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorRedPrimary"
        android:padding="8dp">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:text="@string/item_detected"
            android:textColor="#fff" />

        <TextView
            android:id="@+id/tv_total_data"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_marginEnd="7dp"
            android:hint="10 items detected"
            android:textColor="#fff" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/rl_data"
        android:layout_below="@id/rl_total_data"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <ListView
            android:id="@+id/lv_data"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true" />

    </RelativeLayout>
    <Button
        android:id="@+id/btn_register"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentStart="true"
        android:background="@color/colorRedPrimary"
        android:text="@string/register_all_item"
        android:textAllCaps="false"
        android:textColor="#fff" />
</LinearLayout>

Mia
  • 1
  • 2
  • i have resolved it, the problem is in my tabbed activity layout. you should see my update message above. thanks for your answer! – cleanrun Nov 23 '18 at 07:24
  • @llehcram I was also curious about the activity layout but i'm late. thanks for your inform about update. – Mia Nov 23 '18 at 08:18