Android Studio 上的 ScrollView 按钮消失
Buttons Disappear With ScrollView on Android Studio
没有ScrollView
,我的按钮看起来很好,但在我使用它之后,按钮消失了,我尝试了很多解决方案,但出现的东西只是<TextView>
。
我怎样才能让它们显示为首选?
activity_main.xml
<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"
tools:context=".MainActivity"
android:background="@drawable/background">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="20dp"
android:orientation="vertical">
<TextView
android:id="@+id/HeaderText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="21dp"
android:gravity="right"
android:hapticFeedbackEnabled="false"
android:shadowColor="#A8A8A8"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="25"
android:text="HeaderText"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:textColor="@color/white"
app:layout_constraintBottom_toTopOf="@+id/Button1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="RtlHardcoded" />
<Button
android:id="@+id/Button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="44dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:background="@android:drawable/btn_radio"
android:text="Button1"
app:layout_constraintBottom_toTopOf="@+id/Button2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/HeaderText"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/Button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="1dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:background="@android:drawable/btn_radio"
android:text="Button2"
app:layout_constraintBottom_toTopOf="@+id/Button3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/Button1" />
<Button
android:id="@+id/Button3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="1dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:background="@android:drawable/btn_radio"
android:text="Button3"
app:layout_constraintBottom_toTopOf="@+id/Button4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/Button2" />
<Button
android:id="@+id/Button4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="1dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="364dp"
android:background="@android:drawable/btn_radio"
android:text="Button4"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/Button3" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
MainActivity.java 默认。
It works like this:
问题是您的按钮宽度为零。
<Button
android:id="@+id/Button2"
android:layout_width="0dp" //<------------- HERE
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="1dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:background="@android:drawable/btn_radio"
android:text="Button2"
app:layout_constraintBottom_toTopOf="@+id/Button3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/Button1" />
改变宽度,你就会看到它们。
没有ScrollView
,我的按钮看起来很好,但在我使用它之后,按钮消失了,我尝试了很多解决方案,但出现的东西只是<TextView>
。
我怎样才能让它们显示为首选?
activity_main.xml
<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"
tools:context=".MainActivity"
android:background="@drawable/background">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="20dp"
android:orientation="vertical">
<TextView
android:id="@+id/HeaderText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="21dp"
android:gravity="right"
android:hapticFeedbackEnabled="false"
android:shadowColor="#A8A8A8"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="25"
android:text="HeaderText"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:textColor="@color/white"
app:layout_constraintBottom_toTopOf="@+id/Button1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="RtlHardcoded" />
<Button
android:id="@+id/Button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="44dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:background="@android:drawable/btn_radio"
android:text="Button1"
app:layout_constraintBottom_toTopOf="@+id/Button2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/HeaderText"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/Button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="1dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:background="@android:drawable/btn_radio"
android:text="Button2"
app:layout_constraintBottom_toTopOf="@+id/Button3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/Button1" />
<Button
android:id="@+id/Button3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="1dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:background="@android:drawable/btn_radio"
android:text="Button3"
app:layout_constraintBottom_toTopOf="@+id/Button4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/Button2" />
<Button
android:id="@+id/Button4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="1dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="364dp"
android:background="@android:drawable/btn_radio"
android:text="Button4"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/Button3" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
MainActivity.java 默认。
It works like this:
问题是您的按钮宽度为零。
<Button
android:id="@+id/Button2"
android:layout_width="0dp" //<------------- HERE
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="1dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:background="@android:drawable/btn_radio"
android:text="Button2"
app:layout_constraintBottom_toTopOf="@+id/Button3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/Button1" />
改变宽度,你就会看到它们。