Can't Set Progress Bar in Fresco - android

I am reading the documentation for Fresco, and it says I can create a progress bar for a SimpleDraweeView with the following attribute:
fresco:progressBarImage="#drawable/progress_bar"
or with this code (I modified the example to work in Kotlin and work with a draweeView inside of a recyclerview)
val hierarchy : GenericDraweeHierarchy = GenericDraweeHierarchyBuilder.newInstance(context.resources)
.setProgressBarImage(ProgressBarDrawable())
.build()
holder.draweeView.setHierarchy(hierarchy)
However, in my XML I am getting the "cannot resolve symbol" error in reference to the drawable.
Additionally, the .setHierarchy(hierarchy) is not recognized.
What's going on?
My build.gradle has the following dependencies (among others):
implementation 'com.facebook.fresco:fresco:1.9.0'
implementation 'com.facebook.fresco:animated-gif:1.9.0'
Also, here is the XML layout for the item column for my recyclerview:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:fresco="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<com.facebook.drawee.view.SimpleDraweeView
android:id="#+id/itemImage"
android:layout_width="300dp"
android:layout_height="0dp"
app:layout_constraintHeight_default="percent"
app:layout_constraintHeight_percent="0.7"
app:layout_constraintLeft_toRightOf="parent"
app:layout_constraintRight_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
fresco:progressBarImage="#drawable/progress_bar"
/>
<ToggleButton
android:id="#+id/itemFavoriteButton"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:background="#drawable/ic_favorite"
android:textOff=""
android:textOn=""
android:text=""
app:layout_constraintHeight_default="percent"
app:layout_constraintHeight_percent="0.3"
app:layout_constraintLeft_toRightOf="parent"
app:layout_constraintRight_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="#+id/itemImage" />
</android.support.constraint.ConstraintLayout>

Related

I am getting "message: XML document structures must start and end within the same entity" in Android Studio

I am new to Android Studio. I started building an app. This is the code of my xml file. I can't figure out the problem! This is the exact error code that I am getting."ParseError at [row,col]:[60,1]
Message: XML document structures must start and end within the same entity."
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#121212"
tools:context=".MainActivity"
>
<ImageView
android:id="#+id/imageView"
android:layout_width="844dp"
android:layout_height="1090dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.501"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.988"
app:srcCompat="#drawable/up_notch_adobespark" />
<ImageButton
android:id="#+id/imageButton4"
android:layout_width="50dp"
android:layout_height="54dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.005"
tools:srcCompat="#drawable/more_button" />
<ImageButton
android:id="#+id/imageButton7"
android:layout_width="59dp"
android:layout_height="66dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.997"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.004"
app:srcCompat="#drawable/help_icon" />
<TextView
android:id="#+id/textView"
android:layout_width="165dp"
android:layout_height="36dp"
android:fontFamily="#font/baloo_tamma"
android:text="Hi Josh."
android:textSize="22dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.065"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.158" />
just like broot explained … XML syntax is similar to HTML it has an opening and closing tag, so you need to close every single tag you open in which your case is the constraint layout . just add this line to the end of your xml file
</androidx.constraintlayout.widget.ConstraintLayout>
another advice would be very useful is to avoid using horizontal and vertical bias, I believe that padding(s) and margins(s) are more than enough to help you design the layout you want
and try also using for width and height wrap_content or match parent for detailed and correct measurement for the most phones that will be used. because if you changed the amuleter you are using you will notice that the measurement will be diffrient so as a best practice is to use wrap_content or match parent
Error message is pretty self-explanatory. You opened ConstraintLayout tag at the beginning of the document, but you never closed it. You need to add the following at the end:
</androidx.constraintlayout.widget.ConstraintLayout>

android view inside cardView override corners

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
... />
<androidx.cardview.widget.CardView
app:cardCornerRadius="20dp"
android:layout_width="100sp"
android:layout_height="200sp"
app:layout_constraintBottom_toTopOf="#+id/textView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" >
<ImageView
android:layout_marginTop="0dp"
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="#drawable/ic_launcher_background" />
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
But when I create new project a corners is not override. I do not why I have this and how i can repair this
For assigning cornerRadius to CardView just Use
app:cardCornerRadius="10dp"
in your CardView to assign corner's to your cardView .
And for Rounded ImageView use RoundedImageView library .
First Step :
Add the below dependency to your app level gradle file
implementation 'com.makeramen:roundedimageview:2.3.0'
Second Step :
And in your project level gradle file make sure you have inside your repositories block:
repositories {
mavenCentral()
}
Third Step :
Now just replace your ImageView with the RoundedImageView :
For eg like this :
com.makeramen.roundedimageview.RoundedImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/imageView1"
android:src="#drawable/photo1"
android:scaleType="fitCenter"
app:riv_corner_radius="30dip"
app:riv_border_width="2dip"
app:riv_border_color="#333333"
app:riv_mutate_background="true"
app:riv_tile_mode="repeat"
app:riv_oval="true" />
Here you can change the corner_radius as you like and also if you want to keep it oval as shape then mark it app:riv_oval as true else mark it as false .

Creating an Android launchscreen xml in Flutter project using constraint layout - constraints not found

I wanted to create a new Android launch screen for my Flutter app using constraint layout.
Firstly, I wasn't able to directly open layout builder in Android Studio in my Flutter app project. So using Android Studio, I created a new Android app with an empty activity and used the layout builder to create my layout by setting constraints. I then copied the generated XML into launch_background.xml of my Flutter project - where my previous splashscreen (not using constraint layout) had been working. I added this vectorDrawables.useSupportLibrary = true in the android.defaultConfig in and compile 'com.android.support:appcompat-v7:24.1.1' in dependencies, both in build.gradle.
I'm now unable to run my app because of errors for each constraint:
attribute layout_constraintTop_toTopOf (aka pha.myapp.dep.us:layout_constraintTop_toTopOf) not found.
...and repeat for each constraint.
How have I already tried to fix it?
I tried with this: implementation 'androidx.constraintlayout:constraintlayout:2.0.4' in the
dependencies in build.gradle but my app was stuck building for over
an hour.
I've run flutter clean
I've deleted my entire gradle file.
Am I missing something?
Finally, as reference, this is my XML file. The three drawables exist and have worked before when I haven't used constraint layout.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
>
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
app:srcCompat="#drawable/ic_bg_splash" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="157dp"
android:layout_marginLeft="157dp"
android:layout_marginEnd="157dp"
android:layout_marginRight="157dp"
android:layout_marginBottom="32dp"
app:layout_constraintBottom_toBottomOf="#+id/imageView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0"
app:srcCompat="#drawable/ic_logo" />
<ImageView
android:id="#+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="56dp"
android:layout_marginLeft="56dp"
android:layout_marginEnd="56dp"
android:layout_marginRight="56dp"
android:layout_marginBottom="20dp"
app:layout_constraintBottom_toBottomOf="#+id/imageView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/imageView"
app:srcCompat="#drawable/ic_brandlogotag" />
</androidx.constraintlayout.widget.ConstraintLayout>

Element Button is not allowed here

I created a fragment_b.xml file in my resources/layout folder. On my two buttons I get the following warning:
Element Button is not allowed here
Why is this warning popping up? My code is working fine.
fragment_b.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
<Button
android:id="#+id/btn_fragment_b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/go_to_fragment_c"
app:layout_constraintBottom_toTopOf="#id/btn_nagivate_to_fragment_f"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<Button
android:id="#+id/btn_nagivate_to_fragment_f"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/go_to_fragment_f"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/btn_fragment_b"
android:layout_marginTop="#dimen/a_lot_of_margin"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
This will happen if you don't have the androidx ConstraintLayout library added as a dependency in your gradle files.
In your app/build.gradle file, in the dependencies block, add this:
dependencies {
// ...
implementation "androidx.constraintlayout:constraintlayout:2.0.0-beta3"
}
Of course you can use a different library version, but the androidx.constraintlayout:constraintlayout: part is important.
Once that's done, do a gradle sync and rebuild your project and the warning should go away.
Try change it to:
androidx.appcompat.widget.AppCompatButton
or
com.google.android.material.button.MaterialButton

"unknown drawble resource" error

1) I'm seeing "unknown drawble resource" error when I use:"android:src="#drawble/party""
The complete code is shown below. What's the issue as my "party.jpg" file is under res/drawble folder?
2) I also see an error with "android:layout_alignRight="8dp"" What's the issue here?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="park.hannah.myapplication.MainActivity">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawble/party" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="From. Hyunji"
android:padding="8dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Happy Tuesday!!"
android:layout_alignRight="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</RelativeLayout>
YOU HAVE SYNTAX ERROR
#drawable/party instead of #drawble/party
use this
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/party" />
I also see an error with "android:layout_alignRight="8dp"" What's the
issue here?
you must align a view depend on another view by ID
suggestions
you can also use gravity right instead of android:layout_alignRight for not complex view layouts
try to use LinearLayout easy and comfort for not complex view layouts
rename your drawable from *.jpg to *.png

Categories

Resources