【问题标题】:Android AppCompatButton does look crazy in lower part of the screenAndroid AppCompatButton 在屏幕下部看起来确实很疯狂
【发布时间】:2021-03-03 17:57:45
【问题描述】:

有人解释了 vipager2 中的以下行为以及为什么按下按钮的角度会这样变化?

在第一张图片中,第一个按钮被按下。 在第二个第 6 个按钮(看起来很疯狂)。

在代码中,您可以看到我的布局以及按钮样式的下方。 我确实将按钮更改为材质按钮,但这并没有解决问题。

我不知道这种观点/角度的变化来自哪里。

<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="17">

    <com.google.android.material.textview.MaterialTextView
        android:gravity="center"
        android:layout_gravity="center"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:text="@string/app_name"
        android:layout_weight="1" />

    <androidx.appcompat.widget.AppCompatTextView
        style="@style/rv_title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:textAlignment="center"
        android:gravity="center" />

    <androidx.appcompat.widget.LinearLayoutCompat
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="7"
        android:orientation="vertical"
        android:layout_marginHorizontal="8dp">


        <androidx.appcompat.widget.AppCompatButton
            style="@style/style" />

        <androidx.appcompat.widget.AppCompatButton
            style="@style/style" />

        <androidx.appcompat.widget.AppCompatButton
            style="@style/style" />

    </androidx.appcompat.widget.LinearLayoutCompat>


    <androidx.appcompat.widget.AppCompatTextView
        style="@style/rv_title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:textAlignment="center"
        android:gravity="center" />

    <androidx.appcompat.widget.LinearLayoutCompat
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="7"
        android:orientation="vertical"
        android:layout_marginHorizontal="8dp">

        <androidx.appcompat.widget.AppCompatButton
            android:id="@+id/isearch_button0"
            style="@style/style" />

        <androidx.appcompat.widget.AppCompatButton
            android:id="@+id/isearch_button1"
            style="@style/style" />

        <androidx.appcompat.widget.AppCompatButton
            style="@style/style" />

        <androidx.appcompat.widget.AppCompatButton
            style="@style/style" />


    </androidx.appcompat.widget.LinearLayoutCompat>

</androidx.appcompat.widget.LinearLayoutCompat>

<style name="style">
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:textColor">@android:color/black</item>
    <item name="android:text">@string/templateTypeAnswer_male</item>
    <item name="android:backgroundTint">@android:color/transparent</item>
</style>

【问题讨论】:

  • 显示此布局的 XML 代码
  • 我添加了xml代码

标签: android android-appcompat android-button androidx


【解决方案1】:

在您的style 中,您已将backgroundTint 设置为透明,默认情况下为每个AppCompatButton 添加阴影是不支持的,因此您会看到一些故障。如果你需要真正透明的Button 然后使用background 属性,但是你会失去阴影(因为在“材质”世界中透明物体下没有阴影)。如果您需要灰色模糊背景(又名“仅阴影”),请为此目的使用一些自定义drawable,也设置为background 属性。然后您也可以将StateListAnimator 设置为null - 此属性是“添加”阴影(不是backgroundbackgroundTint),并且按下时elevation 的动画也会发生变化。 null 将删除此功能(在您的style 下方输入)

<item name="android:stateListAnimator">@null</item>

【讨论】:

    猜你喜欢
    • 2011-05-04
    • 1970-01-01
    • 2019-06-12
    • 1970-01-01
    • 2013-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多