繁体   English   中英

使用RelativeLayout偏移中心对齐ProgressBar视图?

[英]Using RelativeLayout to offset center align ProgressBar view?

我有一个ImageView,它用作图像的背景,同时预加载器在屏幕中央水平和垂直对齐。 我设法将progressBar居中,但无法使用边距将其略微抵消。

有人建议使用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 >

尝试这个。

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

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