Android 如何使ScrollView透明?

Android 如何使ScrollView透明?,android,android-layout,android-styles,android-scrollview,Android,Android Layout,Android Styles,Android Scrollview,我有一个包含ConstraintLayout的ScrollView。ConstraintLayout有一个可绘制资源作为其背景:android:background=@drawable/bg\u rounded\u corner\u pin\u bg,它成功地给出了ConstraintLayout圆角。我遇到的问题是,ScrollView显示在ConstraintView的圆角后面,我无法使ScrollView透明: 以下是布局文件: activity_enterpin.xml <?xml

我有一个包含ConstraintLayout的ScrollView。ConstraintLayout有一个可绘制资源作为其背景:
android:background=@drawable/bg\u rounded\u corner\u pin\u bg
,它成功地给出了ConstraintLayout圆角。我遇到的问题是,ScrollView显示在ConstraintView的圆角后面,我无法使ScrollView透明:

以下是布局文件:

activity_enterpin.xml

<?xml version="1.0" encoding="utf-8"?>       
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    android:id="@+id/scrollviewPin"
    android:background="#00000000" // this is where I need transparency
    >

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:maxWidth="@dimen/layout_maxwidth"
        android:padding="@dimen/layout_padding"
        android:background="@drawable/bg_rounded_corner_pin_bg">

        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/title_margintop"
            android:gravity="center"
            android:text="@string/pinlock_title"
            android:textColor="@color/text_title"
            android:textSize="@dimen/textsize_title"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <com.example.isaacmain3.lockscreen.andrognito.pinlockview.IndicatorDots
            android:id="@+id/indicator_dots"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/dot_margintop"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/title" />

        <TextView
            android:id="@+id/attempts"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/attempts_margintop"
            android:textColor="@color/text_attempts"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/indicator_dots" />

        <com.example.isaacmain3.lockscreen.andrognito.pinlockview.PinLockView
            android:id="@+id/pinlockView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/lockview_margin"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/attempts"
            app:layout_constraintVertical_bias="0.1" />

    </android.support.constraint.ConstraintLayout>
</ScrollView>

我已经在ScrollView中使用了背景色,我能够成功地将颜色从我上面评论的字段更改为任何不透明的颜色。我怎样才能摆脱这些角落

这是我用来制作圆角的可绘制文件,以备不时之需:

bg_圆角_pin_bg.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@color/colorPrimaryDark"/>

  <!--  <stroke android:width="2dp"
        android:color="#999999"/>-->

  <!--  <padding android:left="2dp"
        android:top="2dp"
        android:right="2dp"
        android:bottom="2dp"/>-->

    <corners android:bottomRightRadius="20dp"
        android:bottomLeftRadius="20dp"
        android:topLeftRadius="20dp"
        android:topRightRadius="20dp"
        />
</shape>

使用


android:scrollbarThumbVertical=“@null”

styles.xml
中定义一个新主题:

<style name="TransparentActivity" parent="@android:style/Theme.DeviceDefault.Light.NoActionBar">
    <item name="android:windowBackground">@drawable/bg_rounded_corner_pin_bg</item>
    <item name="android:windowIsTranslucent">true</item>
</style>
<activity android:name=".<activity_name>"
        android:theme="@style/TransparentActivity"/>
最后,在活动类中:

DisplayMetrics m = new DisplayMetrics();
getDisplay().getMetrics(m);

WindowManager.LayoutParams params = getWindow().getAttributes();
params.width = m.widthPixels*4/5;
params.height = m.heightPixels*3/4;
params.gravity = Gravity.CENTER;
getWindow().setAttributes(params);

super.onCreate(savedInstanceState);
....

请注意,在调用
super.onCreate()
之前有一段代码。

这是一个通过使用android主题“theme.Holo.dialog”作为对话框使用的活动,请尝试此“android:background=“@android:color/transparent””谢谢!!简单地使用@color/transparent,其中“color/transparent”对我来说是#00000000!!!