簡體   English   中英

無法將具有自己布局的按鈕添加到另一個布局

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

我需要完成以下任務:

1)四個按鈕中的每一個都保存在自己的相對或框架布局中

2) 這四個帶有按鈕的布局通過include標簽添加到另一個更大的布局中

3)這個更大的布局是改變這些按鈕的ID和文本

到目前為止,我做了以下事情:

為了完成任務 #1,我創建了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>

為了完成任務 #2 和 #3,我在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"
    />

我有兩個問題:

1)為什么按鈕不可見?

2) 如何從更大的布局更改按鈕的 ID 和文本?

美好的時光

  1. 我懷疑您是否可以使用包含標簽設置文本
  2. 即使您可以通過這種方式設置文本,也不能將文本設置為相對布局——它不支持文本屬性。

  3. 您不能以這種方式更改按鈕的 ID,

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM