0

I want to create an application that have 5 buttons in bottom of page, when user clicks on the any button, the page will changes but 5buttons remain in bottom of page. now i create this program but when i call setContentView() in other class becuase i call other layout, buttons removed. have ways for remain 5buttons? or i should create 5buttons again in 5layout?

Thanks Cheers

3 Answers3

1

Easiest and Simple way is to make a layout having 5 buttons and it in all your layout files Example

<include layout="@layout/titlebar"/>

Or another way is to use fragments so tht only fragments with change keeping other of your layout stuff same
Edit
OR Use the <merge> Tag
The <merge /> tag helps eliminate redundant view groups in your view hierarchy when including one layout within another. For example, if your main layout is a vertical LinearLayout in which two consecutive views can be re-used in multiple layouts, then the re-usable layout in which you place the two views requires its own root view. However, using another LinearLayout as the root for the re-usable layout would result in a vertical LinearLayout inside a vertical LinearLayout. The nested LinearLayout serves no real purpose other than to slow down your UI performance.

To avoid including such a redundant view group, you can instead use the element as the root view for the re-usable layout. For example:

<merge xmlns:android="http://schemas.android.com/apk/res/android">

    <Button
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:text="@string/add"/>

    <Button
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:text="@string/delete"/>

</merge>

Now, when you include this layout in another layout (using the tag), the system ignores the element and places the two buttons directly in the layout, in place of the tag.

Please go through this link to gain more information about Reusing layouts

Just Variable
  • 892
  • 10
  • 19
0

From what I can gather, I think you are looking for tabs instead of Buttons. Take a look at this.

Community
  • 1
  • 1
Antrromet
  • 15,294
  • 10
  • 60
  • 75
0

Thanks for answer. I read developer link and i add merge and include tag to xml file but the program has errors. Why?

MainActivity.xml

<?xml version="1.0" encoding="utf-8"?>
<include layout="@layout/location"/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<WebView
    android:id="@+id/web_view"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1.0" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/background"
    android:gravity="bottom"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/button_home"
        style="?android:attr/borderlessButtonStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawableTop="@drawable/home_icon"
        android:text="@string/button_home"
        android:textColor="@color/text_home" />

    <Button
        android:id="@+id/button_product"
        style="?android:attr/borderlessButtonStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawableTop="@drawable/product_icon"
        android:onClick="Product"
        android:text="@string/button_product"
        android:textColor="@color/text_product" />

    <Button
        android:id="@+id/button_places"
        style="?android:attr/borderlessButtonStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawableTop="@drawable/places_icon"
        android:onClick="Places"
        android:text="@string/button_places"
        android:textColor="@color/text_places" />

    <Button
        android:id="@+id/button_rewards"
        style="?android:attr/borderlessButtonStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawableTop="@drawable/rewards_icon"
        android:onClick="Rewards"
        android:text="@string/button_rewards"
        android:textColor="@color/text_rewards" />

    <Button
        android:id="@+id/button_more"
        style="?android:attr/borderlessButtonStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawableTop="@drawable/more_icon"
        android:onClick="More"
        android:text="@string/button_more"
        android:textColor="@color/text_more" />
</LinearLayout>

</LinearLayout>

location.xml

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

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView>
<com.google.android.maps.MapView
    android:id="@+id/mapView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clickable="true"
    android:apiKey="0cPRv243zM1_S3ydsNg8MJP9_6BfCp642jOhPvQ"/>
<LinearLayout
    android:id="@+id/zoom"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"/>

</LinearLayout>
</merge> 

what is incorrect? Thank you