0

I want to place those two parts inside a layout to form a loading bar.

wood board
and
loading indicator

The orange indicator needs to be inside the wood board, But I can't find a way to connect them in a proper way...

The final results should look like this
this.

XML File:

<android.support.constraint.ConstraintLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 android:layout_width="match_parent"
 android:layout_height="match_parent">

    <ImageView
        android:id="@+id/wood_board"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <com.menwithandroid.myhookah.gui.LoadingProgressBar
       android:id="@+id/loading_indicator"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content" />

</android.support.constraint.ConstraintLayout>

How can I connect those parts properly? Thanks.

ColdFire
  • 6,764
  • 6
  • 35
  • 51
  • you can easily achieve this using RelativeLayout, give same relation to the views, but question is what do you want to do this ? i mean do you want to show loader on Image view ? – Pradeep Deshmukh May 23 '18 at 13:13
  • The indicator should be inside the socket (on the wood board), so I need to apply margins or another value to determine its location. But I can't use dp or px because it will be messed up on other screen sizes... –  May 23 '18 at 13:23
  • Have the images with the same ratio.. meaning the orange part have the necessary transparent space around this way just you put them within the same parentview – ColdFire May 23 '18 at 13:24

4 Answers4

1

with constraint layouts its very easy... you can place items in the same exact position, and the use android:elevation to ensure that one component is overlays the other.

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
    android:id="@+id/wood_board"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_marginStart="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginBottom="8dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    android:src="@drawable/loading"
    android:elevation="2dp"/>

<ImageView
    android:id="@+id/loading_indicator"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginBottom="8dp"
    android:src="@drawable/bar"
    app:layout_constraintBottom_toBottomOf="@+id/wood_board"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="@+id/wood_board" />

Your solution will look something like this: here

picture

dev_exo
  • 164
  • 1
  • 8
Dracarys
  • 714
  • 7
  • 16
0

It is just imageview inside imageview.The following may work for you.This is the sample code or you can just drag in design section of xml file.

Abhishek Borikar
  • 374
  • 1
  • 5
  • 15
0

Try it out with a RelativeLayout something like this:

    <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center">

           <ImageView
            android:id="@+id/wood_board"
            android:gravity="center"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <com.menwithandroid.myhookah.gui.LoadingProgressBar
           android:id="@+id/loading_indicator"
            android:gravity="center"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content" />


 </RelativeLayout>

And then set the ImageView size accordingly, which would fit into the LoadingProgressBar

Subrata
  • 182
  • 7
0

Thank you all...

I used android.support.constraint.Guideline with app:layout_constraintGuide_percent to determine the location of the indicator inside the wood board by percentages (for different screen sizes compatibility).

It ends up looking like this