简体   繁体   中英

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. I managed to center the progressBar but wasn't able to offset it slightly above using margin.

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 ...

<?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 >

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM