我有一个类似的问题
这是我的XML布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true">
<ImageButton
android:id="@+id/imageButton”
android:layout_width="40dip"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:contentDescription="@string/descrp"
android:scaleType="center"
android:src="@drawable/some_drawable”
android:visibility="visible" />
<TextView
android:id="@+id/textview”
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dip"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:textColor="#FFFFFF"
android:textStyle="bold" />
<ProgressBar
android:id="@+id/progressbar”
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_alignParentBottom="true" />
</RelativeLayout>
如何使进度栏触摸屏幕的边框,而没有进度条和边框之间的任何差距?
我已经为此挣扎了一段时间。我的结论是:对于任意屏幕大小,没有办法用XML 对此行为进行构造。在某些屏幕上的分辨率上,进度栏将始终放错位置。
我的简单解决方案:将progressbar的y设置为编程到超级视图/布局的底部,从而提取了Progressbar高度的一半
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
progressBar.setY(layout.getY() + layout.getHeight() - progressBar.getHeight() / 2);
}
适用于魅力和所有屏幕尺寸。
我找到了一个工作。我基本上是在我的progressbar中添加layout_marginbottom =" - 4DP",将其包装在relativelayout中,并将其对齐到parter视图的底部。将来可能会破坏您的应用程序。对于更好的解决方案设计,使用您自己的自定义绘制的自定义进度栏,您可以正确对齐,并且与ProgressBarstyleHorizontal相比,您可以正确地对齐,并且占据了较少的帆布空间。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true">
<ImageButton
android:id="@+id/imageButton”
android:layout_width="40dip"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:contentDescription="@string/descrp"
android:scaleType="center"
android:src="@drawable/some_drawable”
android:visibility="visible" />
<TextView
android:id="@+id/textview”
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dip"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:textColor="#FFFFFF"
android:textStyle="bold" />
//changes
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:id="@+id/some_other_id"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="-4dp" />
</RelativeLayout></RelativeLayout>
只需在progressbar中添加以下属性
android:minHeight="4dp" // or whatever height you want
android:maxHeight="4dp" // or whatever height you want
完成代码:
<ProgressBar
android:id="@+id/snackbar_progress_crop"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminate="true"
android:indeterminateOnly="false"
android:minHeight="4dp"
android:maxHeight="4dp"
/>