java – Android Studio中相对布局问题中Button上的进度条
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – Android Studio中相对布局问题中Button上的进度条,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3458字,纯文字阅读大概需要5分钟。
内容图文
![java – Android Studio中相对布局问题中Button上的进度条](/upload/InfoBanner/zyjiaocheng/764/bf5baf0a4f674661bc881c116a116b01.jpg)
好的,这是一个奇怪的,我希望有人可以向我解释.
我有一个自定义按钮布局,在按钮中间创建一个带有圆形进度条的按钮.我的XML代码如下.然而,我无法解决的问题是ProgressBar似乎出现在按钮后面.如果我将按钮背景设置为透明以外的任何其他内容,则无法看到进度条.按钮背景为透明,然后我可以看到ProgressBar,但它仍然出现在按钮文本后面.我的理解是视图按照添加的顺序出现.我甚至尝试将视图设置在顶部(view.bringToFront();)并且我尝试删除视图并重新创建它.
为什么进度条出现在按钮后面,我该怎么做才能解决它?
非常感谢
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="@android:color/holo_blue_bright"
android:padding="2dp">
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:text="Button"
android:gravity="center"
android:textColor="@android:color/white"
android:singleLine="true"
android:clickable="false">
</Button>
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:layout_centerInParent="true"
android:visibility="visible"
/>
</RelativeLayout>
代码使用上面的布局
private void setupTableLayout(int NumberOfRows, int NumberOfButtons){
TableLayout.LayoutParams tableParams = new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.MATCH_PARENT);
TableRow.LayoutParams rowParams = new TableRow.LayoutParams(0, android.widget.TableRow.LayoutParams.MATCH_PARENT, 3f);
TableLayout tableLayout = (TableLayout) findViewById(R.id.thetablelayout);
tableLayout.removeAllViews();
for (int i = 0; i < NumberOfRows; i++) {
TableRow tableRow = new TableRow(this);
tableRow.setLayoutParams(tableParams);
RelativeLayout btnOneLayout = (RelativeLayout)getLayoutInflater().inflate(R.layout.custom_button, null);
RelativeLayout btnTwoLayout = (RelativeLayout)getLayoutInflater().inflate(R.layout.custom_button, null);
ProgressBar btnOneProgressBar = (ProgressBar)btnOneLayout.findViewById(R.id.progressBar);
ProgressBar btnTwoProgressBar = (ProgressBar)btnTwoLayout.findViewById(R.id.progressBar);
btnOneLayout.setLayoutParams(rowParams);
btnTwoLayout.setLayoutParams(rowParams);
Button btnOne = (Button)btnOneLayout.findViewById(R.id.button);
btnOne.setText("Btn 1, Row " + i);
btnOne.setId(1001 + i);
Button btnTwo = (Button)btnTwoLayout.findViewById(R.id.button);
btnTwo.setText("Btn 2, Row " + i);
btnTwo.setId(2001 + i);
setButtonClickListener(btnOneLayout, btnOneProgressBar);
setButtonLongClickListener(btnOneLayout, btnOneProgressBar);
tableRow.addView(btnOneLayout); //Add layout, instead of just Button
View adivider = new View(this);
adivider.setLayoutParams(new TableRow.LayoutParams(20, TableRow.LayoutParams.MATCH_PARENT));
adivider.setBackgroundColor(Color.TRANSPARENT);
// This bit of code deals with odd/even numbers of buttons.
if (((i + 1) * 2) < NumberOfButtons + 1) {
tableRow.addView(adivider);
tableRow.addView(btnTwoLayout);
} else {
tableRow.addView(adivider);
btnTwoLayout.setBackgroundResource(android.R.color.transparent);
tableRow.addView(btnTwoLayout);
}
tableLayout.addView(tableRow);
}
}
解决方法:
你可以在android> = 5.0上运行它.在5.0中,他们为视图添加了高程字段. Elevation定义ViewGroup中的z视图顺序.
在这种情况下,按钮具有非零高程值,进度条具有零值提升.
将进度条的高程设置为例如10dp
<ProgressBar
...
android:elevation="10dp"/>
内容总结
以上是互联网集市为您收集整理的java – Android Studio中相对布局问题中Button上的进度条全部内容,希望文章能够帮你解决java – Android Studio中相对布局问题中Button上的进度条所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。