[英]Using RelativeLayout to offset center align ProgressBar view?
I've an ImageView that serves as the background of the image and at the same time a preloader horizontally and vertically aligning in the center of the screen. 我有一个ImageView,它用作图像的背景,同时预加载器在屏幕中央水平和垂直对齐。 I managed to center the progressBar but wasn't able to offset it slightly above using margin.
我设法将progressBar居中,但无法使用边距将其略微抵消。
Some people suggested to use linearLayout and control using android:layout_weight
, however it doesn't work for me as I need to apply my image as background and hence the relativeLayout ... 有人建议使用linearLayout和使用
android:layout_weight
控制,但是它对我不起作用,因为我需要将我的图像用作背景,因此relativeLayout ...
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:background="#FE6869"
android:weightSum="1">
<ImageView
android:src="@drawable/splashscreen"
android:scaleType="centerCrop"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ProgressBar
android:id="@+id/loading_spinner"
style="@style/Widget.AppCompat.ProgressBar"
android:layout_width="65dp"
android:layout_height="65dp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="170dp" />
</RelativeLayout >
Try this. 尝试这个。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:background="#FE6869"
android:weightSum="1">
<ImageView
android:src="@drawable/splashscreen"
android:scaleType="centerCrop"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ProgressBar
android:id="@+id/loading_spinner"
style="@style/Widget.AppCompat.ProgressBar"
android:layout_width="65dp"
android:layout_height="65dp"
android:layout_weight="1"
android:layout_marginTop="170dp" />
</LinearLayout>
</RelativeLayout >
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.