【问题标题】:I don't know what is happening我不知道发生了什么
【发布时间】:2018-03-16 18:21:47
【问题描述】:

我正在尝试在我的布局中添加一个操作栏,但它给了我一个多根标签错误。

这是我的代码。

请帮帮我

编辑:

这是完整的xml

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

<android.support.v7.widget.Toolbar android:id="@+id/my_toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    android:elevation="4dp"
    android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
    xmlns:android="http://schemas.android.com/apk/res/android" />

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:stretchColumns="1"
        android:layout_margin="4dp">

        <CheckBox
            android:id="@+id/c1"
            android:layout_width="match_parent"
            android:layout_height="70dp"
            android:textSize="20sp"
            android:text="@string/c1"
            android:layout_margin="2dp"
            android:onClick="onCheckboxClicked"
            android:background="#00FF00"/>

【问题讨论】:

标签: android


【解决方案1】:

试试这个布局结构:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar
        android:id="@+id/my_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:elevation="4dp"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="4dp"
            android:stretchColumns="1">

            <CheckBox
                android:id="@+id/c1"
                android:layout_width="match_parent"
                android:layout_height="70dp"
                android:layout_margin="2dp"
                android:background="#00FF00"
                android:onClick="onCheckboxClicked"
                android:text="asdf"
                android:textSize="20sp" />

        </TableLayout>

    </ScrollView>
</LinearLayout>

【讨论】:

    【解决方案2】:
    1. ScrollView 只能有一个孩子。如果您想要多个,请将它们包装在一个布局中。
    2. 任何 xml 文件中必须只有一个根布局。了解根标签和 xml 命名空间
       <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_height="match_parent"
        android:layout_width="match_parent">
    
        <android.support.v7.widget.Toolbar
            android:id="@+id/my_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            android:elevation="4dp"
            android:theme="@style/ThemeOverlay.AppCompat.ActionBar" />
    
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    
        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:stretchColumns="1"
            android:layout_margin="4dp">
    
        <CheckBox
            android:id="@+id/c1"
            android:layout_width="match_parent"
            android:layout_height="70dp"
            android:textSize="20sp"
            android:text="@string/c1"
            android:layout_margin="2dp"
            android:onClick="onCheckboxClicked"
            android:background="#00FF00"/>
    
        </TableLayout>
    
        </ScrollView>
    
    </RelativeLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-08
      • 1970-01-01
      相关资源
      最近更新 更多