我想添加ProgressBar上的顶部Button(均为内ConstraintLayout).
<Button
android:id="@+id/sign_in_button"
android:layout_width="280dp"
android:layout_height="75dp"
android:layout_marginBottom="75dp"
android:layout_marginTop="50dp"
android:text="@string/sign_in"
android:textColor="@color/white"
android:textSize="22sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/passwordEditText"
app:layout_constraintVertical_bias="0.0"/>
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="@+id/sign_in_button"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="@+id/sign_in_button"
android:layout_marginBottom="8dp"
app:layout_constraintVertical_bias="0.5"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="@+id/sign_in_button"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="@+id/sign_in_button"/>
Run Code Online (Sandbox Code Playgroud)
但即使在呼吁bringToFront进入ProgressBar后onCreate,它总是留在后面Button.
ProgressBar progressBar = (ProgressBar)findViewById(R.id.progressBar);
progressBar.bringToFront();
Run Code Online (Sandbox Code Playgroud) 我认为标题非常明确我的问题......所以这是我的布局:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/button_action"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login" />
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerInParent="true"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
在android SDKs <21上没问题,ProgressBar正确地显示在Button上并且在Button中居中.但是在Android 5.0上,ProgressBar显示在 Button 后面.
因此,当您在"开发者选项"设置中激活"显示布局边界"选项时,您可以看到它已正确定位,但如果没有该选项,您将无法在屏幕上看到任何内容.
有人知道如何解决这个问题吗?我想这是一个事海拔最近推出的,但我真的不知道该怎么照顾它.为了记录,我正在使用support.v7中最近发布的Theme.AppCompat样式.
编辑:
我还尝试以编程方式应用setElevation(0)和setTranslationY(0)按钮,但它没有改变任何东西.所以我想知道它是否必须处理高程.
先谢谢你们
马蒂厄
android android-progressbar android-button android-5.0-lollipop
在lolipop之前的Android版本中,以下代码有效,图像位于按钮前面.但在android 5中,imageview被放在按钮后面.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button"
android:layout_width="210sp"
android:layout_height="210sp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="@drawable/round_button"
android:drawablePadding="10dip"
android:gravity="center_vertical|center_horizontal" />
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:contentDescription="@string/torch"
android:src="?attr/imageview" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud) 我想在我的视图中显示模态进度"轮"叠加.
ProgressDialog接近,但我不想要对话框背景或边框.
我尝试设置对话框窗口的背景drawable:
this.progressDialog = new ProgressDialog(Main.this);
this.progressDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
this.progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
this.progressDialog.setCancelable(false);
this.progressDialog.setIndeterminate(true);
this.progressDialog.show();
Run Code Online (Sandbox Code Playgroud)
但无济于事(即看起来仍然没有... setBackgroundDrawable代码).
我目前正在尝试创建一个益智游戏,其中我有一个网格,并且每个单元格都应该能够在触摸时显示视觉(并且仅视觉)指示。因此,我打算在自定义视图中使用ViewGroupOverlay(使用 getOverlay()):
在每个CellView
@Override
public boolean onTouchEvent(MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View myView = inflater.inflate(R.layout.overlay, null);
gridView.getOverlay().add(myView);
}
if(event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) {
gridView.getOverlay().clear();
}
return super.onTouchEvent(event);
}
Run Code Online (Sandbox Code Playgroud)
其中 'gridView' 是父级(一个 FrameLayout 包含一个 GridLayout,该 GridLayout 包含多个 CellView(它们是 RelativeLayout));)。但我认为这并不重要......
目前用于overview.xml(只是虚拟代码)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#dddd090d">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Test" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
可悲的是,覆盖视图没有出现在任何地方。
但是,如果我在'onTouchEvent'中使用drawable和以下代码尝试它,它会起作用......但我需要视图而不是drawable来工作......
Drawable myIcon = …Run Code Online (Sandbox Code Playgroud)