-5

I have a Linear Layout with three buttons, and then another Linear Layout that overlays the previous layout. I need to still show one of the buttons from the first layout. How can I achieve that? here is my code so far:

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

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center_vertical|center_horizontal|center"
    android:layout_marginBottom="10dp"
    android:layout_marginLeft="85dp"
    android:layout_marginRight="85dp"
    android:layout_marginTop="20dp"
    android:orientation="vertical"
    android:padding="10dp"
    android:screenOrientation="portrait" >

    <Button
        android:id="@+id/fire_help"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_gravity="center_vertical|center_horizontal|center"
        android:layout_marginBottom="30dp"
        android:layout_weight="1"
        android:background="@drawable/fire_help"
        android:text="@string/fire_service"
        android:textColor="@color/White"
        android:textStyle="bold" />

    <Button
        android:id="@+id/police_help"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_gravity="center_vertical|center_horizontal|center"
        android:layout_marginBottom="30dp"
        android:layout_weight="1"
        android:background="@drawable/police_help"
        android:text="@string/police_help"
        android:textColor="@color/White"
        android:textStyle="bold" />

    <Button
        android:id="@+id/medical_help"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_gravity="center_vertical|center_horizontal|center"
        android:layout_marginBottom="10dp"
        android:layout_weight="1"
        android:background="@drawable/medical_help"
        android:padding="10dp"
        android:text="@string/medical_help_description"
        android:textColor="@color/White"
        android:textStyle="bold"
        android:visibility="visible" >

        <requestFocus />
    </Button>
</LinearLayout>

<LinearLayout
    android:id="@+id/overlay"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/overlay_background"
    android:clickable="true"
    android:orientation="vertical"
    android:screenOrientation="portrait"
    android:visibility="visible" >

    <TableRow
        android:id="@+id/textRow1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@color/overlay_text_background" >

        <TextView
            android:id="@+id/test_mode"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal"
            android:gravity="center"
            android:padding="20dp"
            android:text="@string/test_mode"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="@color/White"
            android:textSize="25sp"
            android:textStyle="bold" />
    </TableRow>

    <TableRow
        android:id="@+id/textRow2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@color/White" >

        <TextView
            android:id="@+id/press_button_text"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:padding="20dp"
            android:text="@string/press_button"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textSize="16sp"
            android:textStyle="bold" />
    </TableRow>

    <RelativeLayout
        android:id="@+id/overlay_button_layout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginLeft="65dp"
        android:layout_marginRight="65dp"
        android:layout_marginTop="160dp"
        android:layout_marginBottom="20dp"
        android:background="@drawable/white_background"
        android:orientation="vertical"
        android:padding="25dp" >

        <Button
            android:id="@+id/overlay_medical_help"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/medical_help"
            android:padding="10dp"
            android:src="@drawable/medical_help"
            android:text="@string/medical_help_description"
            android:textColor="@color/White"
            android:textStyle="bold"
            android:visibility="visible" >

            <requestFocus />
        </Button>
    </RelativeLayout>
</LinearLayout>

Unaiza Khalid
  • 330
  • 2
  • 4
  • 13
  • 2
    what you tried so far. – Rathan Kumar Jun 15 '15 at 07:01
  • 1
    show some code and your approach – Syed Nazar Muhammad Jun 15 '15 at 07:02
  • 1
    If the visibility is GONE, you can't see it. And instead of becoming mand trying to copy a View from another layout, I'd better insert the button in the target layout once and for all. – Phantômaxx Jun 15 '15 at 07:02
  • i tried to have an image on the second linear layout, but it doesn't work for all screen sizes, it covers different screen areas for different sizes – Unaiza Khalid Jun 15 '15 at 07:03
  • 1
    thats a different issue, for multiple screen sizes u have to adopt a different approach of putting same name xml file in different folders of res – Syed Nazar Muhammad Jun 15 '15 at 07:04
  • 1
    `it doesn't work for all screen sizes` Then you have to read this [page](http://developer.android.com/guide/practices/screens_support.html). And [this](https://developer.android.com/training/multiscreen/index.html) one. And [this](http://developer.android.com/training/multiscreen/screensizes.html) one. – Phantômaxx Jun 15 '15 at 07:04
  • see this post too http://stackoverflow.com/questions/25381473/how-to-set-my-android-layout-in-all-devices/25381602#25381602 – Syed Nazar Muhammad Jun 15 '15 at 07:06
  • I don't mean that it is not supporting, what I meant was the second button that I put on second linear layout is not giving the same effect as the first button that was in the first layout for different screens – Unaiza Khalid Jun 15 '15 at 07:09
  • for different size you have to set different width, style or height as per your requirment, obviously the appearence of vertical & land layout view would be different, & if not set properly they will behaive not as accpected – Syed Nazar Muhammad Jun 15 '15 at 07:12

1 Answers1

0

here is how you can do it Programatically

 View b = findViewById(R.id.button);
 b.setVisibility(View.GONE);

or in xml:

<Button ... 
 android:visibility="gone"/>
Asad Mehmood
  • 315
  • 1
  • 3
  • 20