奇怪的布局错误

时间:2018-10-18 15:10:45

标签: android android-layout

我的layout.xml文件包含以下内容。 e_btn_fretboard根本不注册点击。即使按下它,它也不会更改为按下状态的颜色。所有其他按钮都起作用。我将按钮移到了另一个网格单元,然后将其留空。当我移动按钮时,这就是它现在注册点击并更改为按下状态的颜色。

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






    <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView
            android:id="@+id/board_img"
            android:layout_width="0dp"
            android:layout_height="wrap_content"

            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:srcCompat="@drawable/fretboard_12" />
        <ImageView
            android:id="@+id/fretmarker"
            android:layout_width="14dp"
            android:layout_height="14dp"
            android:src="@drawable/fretmarker" />

        <ScrollView
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="30dp"
            android:clipToPadding="false"
            android:fillViewport="false"
            android:scrollbars="vertical"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/board_img"
            app:layout_constraintVertical_bias="0.0">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <GridLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="8dp"
                    android:layout_marginEnd="8dp"
                    android:layout_marginStart="8dp"
                    android:layout_marginTop="8dp"
                    android:columnCount="3"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/noteImage"

                    >

                    <Button
                        android:id="@+id/c_btn_fretboard"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_columnWeight="1"
                        android:layout_column="0"
                        android:layout_row="0"

                        android:text="C"

                        />

                    <Button
                        android:id="@+id/csharp_btn_fretboard"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_column="1"
                        android:layout_columnWeight="1"
                        android:layout_row="0"
                        android:text="C#/Db"
                        android:textAllCaps="false"
                        />



                    <Button
                        android:id="@+id/d_btn_fretboard"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_column="2"
                        android:layout_columnWeight="1"
                        android:layout_row="0"
                        android:text="D"

                        />

                    <Button
                        android:id="@+id/dsharp_btn_fretboard"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_column="0"
                        android:layout_columnWeight="1"
                        android:layout_row="1"
                        android:text="D#/Eb"
                        android:textAllCaps="false" />

                    <Button
                        android:id="@+id/e_btn_fretboard"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_column="1"
                        android:layout_columnWeight="1"
                        android:layout_row="1"
                        android:text="E" />

                    <Button
                        android:id="@+id/f_btn_fretboard"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_column="2"
                        android:layout_columnWeight="1"
                        android:layout_row="1"
                        android:text="F" />

                    <Button
                        android:id="@+id/fsharp_btn_fretboard"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_column="0"
                        android:layout_columnWeight="1"
                        android:layout_row="2"
                        android:text="F#/Gb"
                        android:textAllCaps="false" />

                    <Button
                        android:id="@+id/g_btn_fretboard"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_column="1"
                        android:layout_columnWeight="1"
                        android:layout_row="2"
                        android:text="G" />


                    <Button
                        android:id="@+id/gsharp_btn_fretboard"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_column="2"
                        android:layout_columnWeight="1"
                        android:layout_row="2"
                        android:text="G#/Ab"
                        android:textAllCaps="false" />

                    <Button
                        android:id="@+id/a_btn_fretboard"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_column="0"
                        android:layout_columnWeight="1"
                        android:layout_row="3"
                        android:text="A"
                        android:textAllCaps="false" />

                    <Button
                        android:id="@+id/asharp_btn_fretboard"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_column="1"
                        android:layout_columnWeight="1"
                        android:layout_row="3"
                        android:text="A#/Bb"
                        android:textAllCaps="false"/>

                    <Button
                        android:id="@+id/b_btn_fretboard"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_column="2"
                        android:layout_columnWeight="1"
                        android:layout_row="3"
                        android:text="B" />
                </GridLayout>
            </LinearLayout>
        </ScrollView>

    </android.support.constraint.ConstraintLayout>

</RelativeLayout>

1 个答案:

答案 0 :(得分:0)

尝试首先简化您的布局。 ScrollView中不需要像主RelativeLayout和LinearLayout这样的容器。简化事情可以提高性能,可读性,并减少犯错的可能性。

相关问题