proli2
proli2

Reputation: 1

Android button not visible on the device

On the XML design I add two buttons one of the buttons work without any problem, But the second button invisible on the device. (the two of the buttons stay on a ListView in the XML). I would be happy if someone can help me understood why this is happened and can I fix it. Thanks.

XML (The Settings button is the problem button)-

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="gg.gg.MainActivity">


    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:text="Tasks"
        android:background="#e2e2e2" />

    <ListView
        android:id="@+id/list_todo"
        tools:listitem="@layout/item_todo"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    <Button
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:src="@drawable/settings"
        android:background="@drawable/settings"
        android:onClick="ButtonClick"
        android:id="@+id/settings"
        android:layout_above="@+id/add_task"
        android:layout_alignParentEnd="true" />

    <Button
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:id="@+id/add_task"
    android:src="@drawable/addtask"
    android:background="@drawable/addtask"
    android:layout_alignParentBottom="true"
    android:layout_alignEnd="@+id/settings" />

</RelativeLayout>

Upvotes: 0

Views: 910

Answers (4)

Nancy thakkar
Nancy thakkar

Reputation: 95

<?xml version="1.0" encoding="utf-8"?>

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:mapbox="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=".HomeActivity">

<include
    android:id="@+id/toolbar"
    layout="@layout/toolbar" />



<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/parking"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="6dp"
        android:src="@mipmap/parking_locs" />

    <ImageView
        android:id="@+id/roads"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="6dp"
        android:layout_marginTop="10dp"
        android:src="@mipmap/before_park_car" />

</LinearLayout>

<ImageView
    android:id="@+id/compass"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_margin="10dp"
    android:src="@mipmap/button_my_location" />
</RelativeLayout>

Upvotes: 0

Rajendra
Rajendra

Reputation: 504

enter image description hereYour layout should be as follows:

<?xml version="1.0" encoding="utf-8"?>
        <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
                     android:layout_width="match_parent"
                     android:layout_height="match_parent" >

        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                        xmlns:tools="http://schemas.android.com/tools"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        tools:context="gg.gg.MainActivity">


            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:layout_alignParentTop="true"
                android:id="@+id/textview"
                android:text="Tasks"
                android:background="#e2e2e2" />

            <ListView
                android:id="@+id/list_todo"
                tools:listitem="@layout/item_todo"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_above="@+id/linearlayout"
                android:layout_below="@+id/textview"
                />

            <LinearLayout
                android:id="@+id/linearlayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:orientation="vertical"
                >
            <Button
                android:layout_width="60dp"
                android:layout_height="60dp"
                android:src="@drawable/settings"
                android:background="@drawable/settings"
                android:onClick="ButtonClick"
                android:id="@+id/settings"

                />

            <Button
                android:layout_width="60dp"
                android:layout_height="60dp"
                android:id="@+id/add_task"
                android:src="@drawable/addtask"
                android:background="@drawable/addtask"

                 />
            </LinearLayout>
        </RelativeLayout>

Upvotes: 1

Nidhi
Nidhi

Reputation: 777

I think what you are trying to achieve is floationActionButton. Try this out:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="gg.gg.MainActivity">


        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:layout_alignParentTop="true"
            android:id="@+id/textview"
            android:text="Tasks"
            android:background="#e2e2e2" />

        <ListView
            android:id="@+id/list_todo"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/textview"
            />

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:layout_margin="@dimen/fab_margin"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:src="@android:drawable/ic_dialog_email" />

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:layout_margin="@dimen/fab_margin"
            android:layout_above="@+id/fab"
            android:layout_alignParentRight="true"
            android:src="@android:drawable/ic_dialog_email" />
    </RelativeLayout>
    </FrameLayout>

Upvotes: 0

Nancy thakkar
Nancy thakkar

Reputation: 95

Use Floating action button for this.

Upvotes: 0

Related Questions