我正在尝试构建一个在Android当前视图顶部滑动的滑块。我使用此处https://github.com/mancj/SlideUp-Android中的SlideUp库构建了滑块。滑块将内部RelativeLayout作为视图源。当我拉起滑块时,它最终会在CardView后面。我查看了库中的所有方法,并且没有一个允许您将滑块移动到前台。我还尝试使用.bringToFront()
方法将滑块视图置于前景。在.xml文件中的CardView之前移动滑块视图也不执行任何操作。有没有一个很好的方法将滑块带到前台......或者CardView在后台? (不隐藏CardView)
JAVA
//code to build slider
View slideView = findViewById(R.id.slider);
//tried putting slideView.bringToFront() here before passing it to the object but that did nothing
SlideUp slideUp = new SlideUpBuilder(slideView)
.withStartState(SlideUp.State.HIDDEN)
.withStartGravity(Gravity.BOTTOM)
.build();
//code to bring up slider. View "share" exists, it's just irrelevant so I didn't include in the .xml file
buttonView.findViewById(R.id.share).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//tried putting slideView.bringToFront() here as well
slideUp.toggle(); //toggles slider up/down
}
});
XML
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:background="@color/background"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="60dp">
</android.support.v7.widget.CardView>
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/slider"
android:background="@color/primary">
</RelativeLayout>
</RelativeLayout>
答案 0 :(得分:0)
我明白了。我发现我可以为滑块添加android:elevation="2dp"
,为CardView添加0dp