简体   繁体   中英

Can't add Buttons with their own layouts to another layout

I need to accomplish the following tasks:

1) each of four buttons is held inside its own Relative or Frame layout

2) these four layouts with buttons inside them are added to another bigger layout thru include tag

3) this bigger layout is to change the IDs and text of these buttons

So far I have made the following things:

To accomplish the Task #1, I created res/layout/big_button_layout.xml

<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="wrap_content"
tools:showIn="@layout/activity_main">
<my.planner.BigButton
    android:id="@+id/nonameButton"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text=""
/>

</RelativeLayout>

To accomplish the Tasks #2 and #3, I created the bigger layout in res/layout/big_buttons_layout.xml

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

<include
    layout="@layout/big_button_layout"
    android:id="@+id/button1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:text="@string/title1"
    />

<include
    layout="@layout/big_button_layout"
    android:id="@+id/button2"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:text="@string/title2"
    />

<include
    layout="@layout/big_button_layout"
    android:id="@+id/button3"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:text="@string/title3"
    />

<include
    layout="@layout/big_button_layout"
    android:id="@+id/button4"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:text="@string/title4"
    />

I have two problems:

1) Why are buttons not visible?

2) How do I change IDs and text of the buttons from the bigger layout?

Nice time pass

  1. I doubt whether you can set text with include tag
  2. Even if you can set text this way, you can not set text to relative layout - it doesn't support text attribute.

  3. You can not change IDs of buttons this way,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM