Skip to content

Commit

Permalink
demo for Gloading.getDefault().cover(view) usage with ConstraintLayout
Browse files Browse the repository at this point in the history
  • Loading branch information
luckybilly committed Aug 15, 2019
1 parent 0fb78ce commit e283a16
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.DisplayMetrics;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.billy.android.loading.Gloading;
import com.billy.android.loadingstatusview.BaseActivity;
Expand Down Expand Up @@ -38,7 +38,7 @@ protected void onCreate(Bundle savedInstanceState) {

DisplayMetrics dm = getResources().getDisplayMetrics();
int size = dm.widthPixels * 3 / 4;
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) imageView.getLayoutParams();
ViewGroup.LayoutParams layoutParams = imageView.getLayoutParams();
layoutParams.width = size;
layoutParams.height = size;
//failed by an error image url
Expand All @@ -50,7 +50,7 @@ protected void initLoadingStatusViewIfNeed() {
//override this method in subclass to do special initialization
if (mHolder == null) {
//wrap view with default loading status view
mHolder = Gloading.getDefault().wrap(imageView).withRetry(new Runnable() {
mHolder = Gloading.getDefault().cover(imageView).withRetry(new Runnable() {
@Override
public void run() {
onLoadRetry();
Expand Down
34 changes: 22 additions & 12 deletions app/src/main/res/layout/activity_wrap_single_view.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
<?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.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"
android:background="@color/main_bg"
android:padding="10dp"
>

<ImageView
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:background="#44ff0000"
android:id="@+id/content_view"
android:visibility="visible"
android:layout_width="300dp"
android:layout_height="300dp"
/>

<TextView
android:text="@string/wrap_single_view"
android:textColor="@android:color/white"
android:textSize="16sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
/>

<ImageView
android:id="@+id/content_view"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_centerInParent="true"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_goneMarginTop="30dp"
app:layout_constraintTop_toBottomOf="@+id/content_view"
/>

</RelativeLayout>
</android.support.constraint.ConstraintLayout>

0 comments on commit e283a16

Please sign in to comment.