The crash only happens on few old devices, so far in two lollipop
devices.
I am using saripar library for validation.
android.view.InflateException: Binary XML file line #17: Error inflating class TextView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.widget.Editor.showError(Editor.java:353)
at android.widget.Editor.onFocusChanged(Editor.java:1117)
at android.widget.TextView.onFocusChanged(TextView.java:8115)
at android.view.View.handleFocusGainInternal(View.java:4946)
at android.view.View.requestFocusNoSearch(View.java:7660)
at android.view.View.requestFocus(View.java:7639)
at android.view.View.requestFocus(View.java:7606)
at android.view.View.requestFocus(View.java:7585)
at com.aez.editprofile.ActivityEditProfile.onValidationFailed(ActivityEditProfile.java:621)
at com.mobsandgeeks.saripaar.Validator.triggerValidationListenerCallback(Validator.java:721)
at com.mobsandgeeks.saripaar.Validator.validateFieldsWithCallbackTill(Validator.java:697)
at com.mobsandgeeks.saripaar.Validator.validateUnorderedFieldsWithCallbackTill(Validator.java:679)
at com.mobsandgeeks.saripaar.Validator.validate(Validator.java:334)
at com.mobsandgeeks.saripaar.Validator.validate(Validator.java:295)
at com.aez.editprofile.ActivityEditProfile.btnSubmitProfileData(ActivityEditProfile.java:705)
at com.aez.editprofile.ActivityEditProfile_ViewBinding$3.doClick(ActivityEditProfile_ViewBinding.java:96)
at butterknife.internal.DebouncingOnClickListener.onClick(DebouncingOnClickListener.java:22)
at android.view.View.performClick(View.java:4764)
at android.view.View$PerformClick.run(View.java:19844)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5349)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
Caused by: java.lang.RuntimeException: Failed to resolve attribute at index 24
at android.content.res.TypedArray.getColor(TypedArray.java:401)
at android.widget.TextView.(TextView.java:737)
at android.widget.TextView.(TextView.java:674)
at android.support.v7.widget.AppCompatTextView.(AppCompatTextView.java:75)
at android.support.v7.widget.AppCompatTextView.(AppCompatTextView.java:71)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:103)
at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1024)
at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1081)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:725)
Part of the xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/TextInputLayout_Theme">
<EditText
android:id="#+id/LastNameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Last Name*"
android:inputType="textPersonName"
android:imeOptions="actionNext"
android:theme="#style/EditText_Theme" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
If anyone is looking , in my case the .seterror inside any EditText without support edittext
housed by
<android.support.design.widget.TextInputLayout
is the issue so i had to remove support design widget , now its working fine.
this happens on my LG G2 Lollipop version & a low end Samsung on Lollipop.
sample of working xml
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/text_input_FirstNameEditText">
<android.support.design.widget.TextInputEditText
android:id="#+id/FirstNameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="First Name *"
android:imeOptions="actionNext"
android:inputType="textPersonName|textCapWords"
android:theme="#style/EditText_Theme_without_Special"
android:textColorHint="#color/font_red"/>
</android.support.design.widget.TextInputLayout>
Related
My app fails to start because of Error inflating class ImageButton, Because of this the phone says "app has stopped" Etc.
I am using firebase test lab to debug the problem
the Errors occur on samsung devices specifically A20, s7 Edge , s7(tested with firebase same problem)
I am new to android and have tried many solutions from google and SO none have worked sofar
Here is the error report on firebase
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.smartpractice.smartpracticesmartapp/com.smartpractice.myapplication.MainActivity}: android.view.InflateException: Binary XML file line #117: Binary XML file line #117: Error inflating class ImageButton
FATAL EXCEPTION: main
Process: com.smartpractice.smartpracticesmartapp, PID: 26921
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.smartpractice.smartpracticesmartapp/com.smartpractice.myapplication.MainActivity}: android.view.InflateException: Binary XML file line #117: Binary XML file line #117: Error inflating class ImageButton
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3253)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
at android.app.ActivityThread.access$1100(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: android.view.InflateException: Binary XML file line #117: Binary XML file line #117: Error inflating class ImageButton
at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.smartpractice.myapplication.MainActivity.onCreate(MainActivity.java:14)
at android.app.Activity.performCreate(Activity.java:6876)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)
... 9 more
Caused by: android.view.InflateException: Binary XML file line #117: Error inflating class ImageButton
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:794)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:847)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:855)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
at android.view.LayoutInflater.inflate(LayoutInflater.java:527)
... 17 more
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f070089
at android.content.res.Resources.getValue(Resources.java:2558)
at androidx.appcompat.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:331)
at androidx.appcompat.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:198)
at androidx.appcompat.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:191)
at androidx.appcompat.content.res.AppCompatResources.getDrawable(AppCompatResources.java:102)
at androidx.appcompat.widget.AppCompatImageHelper.loadFromAttributes(AppCompatImageHelper.java:59)
at androidx.appcompat.widget.AppCompatImageButton.<init>(AppCompatImageButton.java:79)
at androidx.appcompat.widget.AppCompatImageButton.<init>(AppCompatImageButton.java:69)
at androidx.appcompat.app.AppCompatViewInflater.createImageButton(AppCompatViewInflater.java:202)
at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:122)
at androidx.appcompat.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1266)
at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1316)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:758)
Here is the 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"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/relativeLayout4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/ic_launcher_background"
tools:context=".MainActivity">
<com.google.android.flexbox.FlexboxLayout
android:id="#+id/flexboxLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
app:alignContent="stretch"
app:alignItems="stretch"
app:flexWrap="wrap"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.863"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/guideline7">
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="48dp"
android:fontFamily="#font/nunito"
android:gravity="center_horizontal"
android:text="#string/welcome_to_smartpractice"
android:textSize="24sp"
app:fontFamily="#font/nunito"
app:layout_alignSelf="baseline"
tools:layout_editor_absoluteY="100dp"
tools:targetApi="jelly_bean" />
<TextView
android:id="#+id/textView7"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorPrimaryDark"
android:gravity="center_horizontal|fill_vertical"
android:text="#string/docsharesmart"
android:textColor="#color/ic_launcher_background"
app:layout_alignSelf="flex_end"
tools:layout_editor_absoluteY="16dp" />
</com.google.android.flexbox.FlexboxLayout>
<com.google.android.flexbox.FlexboxLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
app:alignContent="center"
app:alignItems="stretch"
app:flexDirection="row"
app:flexWrap="nowrap"
app:justifyContent="space_between"
app:layout_constraintBottom_toTopOf="#+id/guideline7"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="#+id/imageView3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="#string/logo1"
app:layout_alignSelf="center"
app:srcCompat="#drawable/smartpractice_logo_02"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="-46dp" />
<ImageButton
android:id="#+id/LoginScreen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#null"
android:contentDescription="#string/loginscreen"
app:layout_alignSelf="center"
app:layout_wrapBefore="false"
app:srcCompat="#drawable/ic_more_vert_black_24dp"
tools:layout_editor_absoluteX="248dp"
tools:layout_editor_absoluteY="134dp" />
</com.google.android.flexbox.FlexboxLayout>
<com.google.android.flexbox.FlexboxLayout
android:id="#+id/flexboxLayout2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:alignContent="stretch"
app:alignItems="stretch"
app:flexWrap="wrap"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/flexboxLayout"
app:layout_constraintVertical_bias="0.146">
Here is line 117 from the error
<ImageButton
android:id="#+id/UploadButton"
android:layout_width="300dp"
android:layout_height="209dp"
android:background="#android:color/transparent"
app:layout_constraintTop_toBottomOf="#+id/flexboxLayout"
app:srcCompat="#drawable/upload_files_upload"
android:contentDescription="#string/todo" />
</com.google.android.flexbox.FlexboxLayout>
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="185dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
It means upload_files_upload is not found in drawble folder, well this can be a case, where your file may present in drawable-24 but not in drawble folder, in that case this problem still arise. The point is your file must be in all drawble folder.
The reason for your error is that the upload_files_upload is not in your drawable folder :
<ImageButton
android:id="#+id/UploadButton"
android:layout_width="300dp"
android:layout_height="209dp"
android:background="#android:color/transparent"
app:layout_constraintTop_toBottomOf="#+id/flexboxLayout"
app:srcCompat="#drawable/upload_files_upload"// this line
android:contentDescription="#string/todo" />
I have solved The Issue I changed app:srcCompat="#drawable/upload_files_upload"// to android:src="#drawable/upload_files_upload"
So the problem was by app:srcCompat I changed it to Android:src and it works fine now
I am getting following error for the line #30 i.e. first line of first EditText in the provided code. This XML is basically associated with an Activity. The error is while binding XML inside activity
setContentView(R.layout.activity_login)
The error is as follows:
Caused by android.view.InflateException: Binary XML file line #30: Binary XML file line #30: Error inflating class EditText
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.pockethcm.greytrix.test.LoginActivity.onCreate(LoginActivity.kt:39)
at android.app.Activity.performCreate(Activity.java:6268)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2370)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2477)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1345)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5468)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:781)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:671)
I have tried couple of things explained in other answers but none of them actually helped me. I am not using any drawable resource for that EditText.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
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:background="#drawable/login_bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.pockethcm.greytrix.test.LoginActivity"
>
<LinearLayout
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:paddingStart="#dimen/_20sdp"
android:paddingEnd="#dimen/_20sdp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/login_layout">
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/profile_image"
android:layout_width="match_parent"
android:layout_height="96dp"
android:src="#drawable/pocketlogosplash"
app:civ_border_width="2dp"
app:civ_circle_background_color="#color/colorWhite"
app:civ_border_color="#bcbcbc"/>
<EditText
android:layout_width="match_parent"
android:backgroundTint="#color/colorWhite"
android:layout_height="wrap_content"
android:hint="Company Code"
android:textColorHint="#color/colorWhite"
android:layout_marginTop="20dp"
android:drawableStart="#drawable/ic_store_white_24dp"
android:drawablePadding="10dp"
android:textColor="#color/colorWhite"
android:id="#+id/company_code"
android:imeOptions="actionNext"
android:maxLines="1"
android:singleLine="true"/>
<EditText
android:layout_width="match_parent"
android:backgroundTint="#color/colorWhite"
android:layout_height="wrap_content"
android:hint="Employee Code"
android:textColorHint="#color/colorWhite"
android:layout_marginTop="20dp"
android:drawableStart="#drawable/ic_person_black_24dp"
android:drawablePadding="10dp"
android:textColor="#color/colorWhite"
android:id="#+id/employee_code"
android:drawableTint="#color/colorWhite"
android:imeOptions="actionNext"
android:maxLines="1"
android:singleLine="true"/>
</LinearLayout>
</ScrollView>
EditText widget should load normally but the activity is crashing with error above.
Providing additional info:
compileSdkVersion 28
minSdkVersion 21
targetSdkVersion 28
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.31"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
You should set left drawable programmatically if its vector for pre kitkat.
company_code.setCompoundDrawablesWithIntrinsicBounds(AppCompatResources.getDrawable(this,R.drawable.ic_store_white_24dp), null, null, null);```
Which android version you are using, I think you use Vector Drawable in EditText, But Vector Drawable support after KitKat.
After updating the android studio to version 3.1.2 & gradle to version 4.4, I've faced weird problem to show snackbar in an activtiy.
here is the code:
#BindView(R.id.layout_coordinator)
CoordinatorLayout coordinatorLayout;
Snackbar.make(coordinatorLayout,"hello", Snackbar.LENGTH_LONG).show();
my XMl layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/layout_coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Activities.LoginActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="70dp"
android:paddingRight="70dp">
<EditText
android:id="#+id/edtMobileNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/txt_RegisterTitle"
android:layout_marginTop="19dp"
android:gravity="center"
android:hint="#string/enterYourMobilePhone"
android:inputType="number"
android:maxLength="11"
android:maxLines="1" />
<Button
android:id="#+id/btn_Confirm"
android:layout_width="130dp"
android:layout_height="40dp"
android:layout_below="#+id/edtMobileNumber"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:background="#drawable/button_background_green"
android:text="#string/confirm"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white" />
</RelativeLayout>
</ScrollView>
</android.support.design.widget.CoordinatorLayout>
And this is the errro I've got:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.company.myproject/com.company.myproject.Activities.LoginActivity}: android.view.InflateException: <merge /> can be used only with a valid ViewGroup root and attachToRoot=true
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2702)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2767)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5951)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
Caused by: android.view.InflateException: <merge /> can be used only with a valid ViewGroup root and attachToRoot=true
at android.view.LayoutInflater.inflate(LayoutInflater.java:476)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at android.support.design.widget.Snackbar.make(Snackbar.java:143)
at com.company.myproject.Activities.LoginActivity.onCreate(LoginActivity.java:98)
as you can see, the error is about inflating layout but can't understand the reason:
Caused by: android.view.InflateException: can be used only with a valid ViewGroup root and attachToRoot=true
It must be mentioned that I've used every solution that are suggested :
my support design version is : implementation com.android.support:design:27.1.1'
the activtiy is extend from AppCompatActivity
The AppTheme is Theme.AppCompat.Light.NoActionBar
I've used getWindow().getDecorView().findViewById(R.id.layout_coordinator), but nothing is solved
be glad someone could help me.
Finally, I've found the solution:
There is a MERGE tag in the snackbar layout that cause exception while inflating layout. By commenting the related row, the problem is solved.
I'm using Android Studio and I would like to be able to pickup am image from the gallery, resize it and make it fit inside a rounded square (of about 300x300px) by maintening the correct aspect ratio.
At the moment, I'm able to resize it and display it as a circle.
FixBitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
bitmap_to_save = scaleBitmapAndKeepRation(FixBitmap, 320, 320);
RoundedBitmapDrawable roundDrawable = RoundedBitmapDrawableFactory.create(getResources(), bitmap_to_save);
roundDrawable.setCircular(true);
p_avatar.setImageDrawable(roundDrawable);
However, I would like to know if it is possible to make the bitmap look like my attached image. Moreover, it would be important for me to resize the image without losing the original aspect ratio.
It is not exactly a well square rounded figure, so I'm not sure that it is possible to do it in Android.
Please, keep in mind that I dinamycally change the imageview inside the code depending on the user actions. So this is not a static image, I replace the original content with a new one if the user upload a new image.
EDIT 1 on May, 20
This is my XML code for the imageview "avatar":
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/ll_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="loginpackage.social.com.ui.profile.ProfileActivity">
<include layout="#layout/custom_toolbar_shadow" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingTop="#dimen/_20sdp">
<ImageView
android:id="#+id/avatar"
android:layout_width="137dp"
android:layout_height="150dp"
android:layout_gravity="center"
android:clickable="true"
android:paddingBottom="#dimen/_10sdp"
android:paddingTop="#dimen/_10sdp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_20sdp"
android:orientation="vertical"
android:paddingLeft="#dimen/_16sdp"
android:paddingRight="#dimen/_16sdp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/profileActivity_name"
android:textSize="#dimen/_14sdp" />
<EditText
android:id="#+id/et_fullname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_5sdp"
android:background="#color/colorWhite"
android:hint="#string/signActivity_fullname"
android:imeOptions="actionDone"
android:inputType="textNoSuggestions"
android:maxLines="1"
android:padding="#dimen/_10sdp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_10sdp"
android:text="#string/profileActivity_email"
android:textSize="#dimen/_14sdp" />
<EditText
android:id="#+id/et_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_5sdp"
android:background="#drawable/editext_back_login"
android:hint="#string/mainActivity_email"
android:imeOptions="actionNext"
android:inputType="textEmailAddress|textNoSuggestions"
android:maxLines="1"
android:padding="#dimen/_10sdp" />
<Button
android:id="#+id/btn_update"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_20sdp"
android:background="#color/colorSignuoBtn"
android:text="#string/profileActivity_update"
android:textColor="#color/colorWhite"
android:textSize="#dimen/_12sdp"
android:visibility="invisible" />
<TextView
android:id="#+id/txt_logout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="#dimen/_10sdp"
android:layout_marginTop="#dimen/_20sdp"
android:background="#drawable/button_logout_profile"
android:foreground="?attr/selectableItemBackgroundBorderless"
android:gravity="center"
android:paddingBottom="#dimen/_12sdp"
android:paddingTop="#dimen/_12sdp"
android:text="#string/profileActivity_logout"
android:textSize="#dimen/_12sdp" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
EDIT 2
At the moment, I'm using Picasso to round the image and it seems to work well.
The problem is that I would like to keep always the same picture size (350x350px) and the aspect ratio. How is it possible to do it?
Transformation transformation = new RoundedTransformationBuilder()
.borderColor(Color.GREEN)
.borderWidthDp(2)
.cornerRadiusDp(15)
.oval(false)
.build();
Picasso.get().load("http://www.server.com/uploads/avatars/"+Conts.USERINFO.getId()).transform(transformation).memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE).networkPolicy(NetworkPolicy.NO_CACHE) .into(p_avatar);
EDIT3:
<com.makeramen.roundedimageview.RoundedImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/avatar"
android:layout_width="160dp"
android:layout_height="160dp"
android:src="#drawable/adduserprofile"
android:scaleType="centerCrop"
app:riv_border_width="2dip"
app:riv_border_color="#333333"
app:riv_mutate_background="true"
app:riv_oval="false"
app:riv_corner_radius_bottom_left="20dp"
app:riv_corner_radius_top_right="20dp"
/>
Why if I set a different value for riv_corner_radius_top_right, then the app crashes?
For example, if I set:
app:riv_corner_radius_bottom_left="20dp"
app:riv_corner_radius_top_right="10dp"
I get this error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: loginpackage.social.com, PID: 25495
java.lang.RuntimeException: Unable to start activity ComponentInfo{loginpackage.social.com/loginpackage.social.com.ui.profile.ProfileActivity}: android.view.InflateException: Binary XML file line #24: Error inflating class com.makeramen.roundedimageview.RoundedImageView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2689)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2754)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5938)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
Caused by: android.view.InflateException: Binary XML file line #24: Error inflating class com.makeramen.roundedimageview.RoundedImageView
at android.view.LayoutInflater.createView(LayoutInflater.java:640)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:750)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at loginpackage.social.com.ui.profile.ProfileActivity.onCreate(ProfileActivity.java:93)
at android.app.Activity.performCreate(Activity.java:6288)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2642)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2754)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5938)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:614)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:750)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at loginpackage.social.com.ui.profile.ProfileActivity.onCreate(ProfileActivity.java:93)
at android.app.Activity.performCreate(Activity.java:6288)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2642)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2754)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5938)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
Caused by: java.lang.IllegalArgumentException: Multiple nonzero corner radii not yet supported.
at com.makeramen.roundedimageview.RoundedDrawable.setCornerRadius(RoundedDrawable.java:507)
at com.makeramen.roundedimageview.RoundedImageView.updateAttrs(RoundedImageView.java:368)
at com.makeramen.roundedimageview.RoundedImageView.updateDrawableAttrs(RoundedImageView.java:318)
at com.makeramen.roundedimageview.RoundedImageView.<init>(RoundedImageView.java:163)
at com.makeramen.roundedimageview.RoundedImageView.<init>(RoundedImageView.java:86)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:614)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:750)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at loginpackage.social.com.ui.profile.ProfileActivity.onCreate(ProfileActivity.java:93)
at android.app.Activity.performCreate(Activity.java:6288)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2642)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2754)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5938)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
You should not give your time to manage these types of logics if you are working on projects in company.
Instead you can just use libraries which have already done great work.
See https://github.com/vinc3m1/RoundedImageView
Your ImageView will be like
<com.makeramen.roundedimageview.RoundedImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/imageView1"
android:src="#drawable/photo1"
android:scaleType="centerCrop"
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" />
and dependency
repositories {
mavenCentral()
}
dependencies {
compile 'com.makeramen:roundedimageview:2.3.0'
}
Update
You seem new to android, if you don't understand id and src, no worries!
Basically id is an unique id that you have created and you refer to
imageView1 if you do findViewById(R.id.imageView1) in your java code.
for more info about id : Difference between "#id/" and "#+id/" in Android
src is the source image file for that image, that is located in your drawables directory.
About your issue
You can use different ImageView ScaleType that matches your requirement.
I think you use android:scaleType="centerCrop" that fit your image at imageView.
I also edited scaleType in above answer. If that does not fit your requirement you can use any of these scale type
Update 2 for setting width and height, you can set layout_width and layout_height attribute. like below.
<com.makeramen.roundedimageview.RoundedImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/imageView1"
android:src="#drawable/photo1"
android:scaleType="centerCrop"
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"
android:layout_width="350dp"
android:layout_height="350dp"/>
see What is the difference between "px", "dip", "dp" and "sp"? for more detail about sp, dp, px in android.
I wrote a MaskView that lets you mask images to any shape, including holes in the middle and partial transparency. It's a lot of code, and I wrote it a long time ago so I wouldn't even use it myself without reviewing it. But the essence of it is an ImageView that takes an alpha mask. When it draws itself, it draws two bitmaps for itself and whatever is behind it, and combines them using the mask.
I am trying to create a page in android app. It is working fine in all the mobiles except in the mobile which is having Android 8.0. Here is the XML file code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/bg3_logo"
>
<TextView
android:id="#+id/text1d"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="14dp"
android:enabled="true"
android:maxLength="50"
android:text="Welcome Customer xxxxxx"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:id="#+id/text2d"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:enabled="true"
android:maxLength="50"
android:text="" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/imageButton1"
android:gravity="center"
android:singleLine="false"
android:text=""
android:textSize="12dp" />
<TextView
android:id="#+id/text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/text2"
android:enabled="true"
android:maxLength="50"
android:text=""
android:textSize="12dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/imageButton12"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_below="#+id/textView3"
android:layout_marginRight="14dp"
android:background="#drawable/rotate6"
android:contentDescription="From Date" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="-10dp"
android:layout_gravity="right">
<ImageButton
android:id="#+id/imageButtondl"
android:layout_width="50dip"
android:layout_height="50dip"
android:background="#drawable/logout"
android:contentDescription="Logout" />
</LinearLayout>
<ListView
android:id="#+id/mylist"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
/>
<Button
android:id="#+id/btn_static"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="EDIT"/>
</LinearLayout>
I was not able to get the log cat as my emulator was not in a working mode due to restriction of proxy server in our domain. Please help me out guys
Finally able to get the Stack trace by sending it to mail
java.lang.RuntimeException: Unable to start activity ComponentInfo{kvbank.kvb_ebook/kvbank.kvb_epassbook.dummy}: android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2946)
at android.app.ActivityThread.startActivityNow(ActivityThread.java:2744)
at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:136)
at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:348)
at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:769)
at android.widget.TabHost.setCurrentTab(TabHost.java:423)
at android.widget.TabHost.addTab(TabHost.java:233)
at kvbank.kvb_epassbook.TabDemo.onCreate(TabDemo.java:87)
at android.app.Activity.performCreate(Activity.java:6998)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1230)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2899)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3046)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1688)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6809)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class <unknown>
Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class <unknown>
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:720)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:788)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:432)
at android.app.Activity.setContentView(Activity.java:2677)
at kvbank.kvb_epassbook.dummy.onCreate(dummy.java:190)
at android.app.Activity.performCreate(Activity.java:6998)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1230)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2899)
at android.app.ActivityThread.startActivityNow(ActivityThread.java:2744)
at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:136)
at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:348)
at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:769)
at android.widget.TabHost.setCurrentTab(TabHost.java:423)
at android.widget.TabHost.addTab(TabHost.java:233)
at kvbank.kvb_epassbook.TabDemo.onCreate(TabDemo.java:87)
at android.app.Activity.performCreate(Activity.java:6998)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1230)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2899)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3046)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1688)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6809)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 6: TypedValue{t=0x2/d=0x101009b a=1}
at android.content.res.TypedArray.getColorStateList(TypedArray.java:538)
at android.widget.TextView.<init>(TextView.java:910)
at android.widget.TextView.<init>(TextView.java:824)
at android.widget.TextView.<init>(TextView.java:820)
... 37 more
SOLUTION
Issue got solved. I am using "android:theme="#android:style/Theme.Holo""
for my dummy class in android manifest which is not defined. removing
this line solved my issue
As you said, you are not able to get Log file. I'm not pretty much sure on the reason behind this. You may try this.
1. Unexpected text /> in your xml below the Listview myList. Remove that part
Even you can see warning in your XML with Unexpected text found in file: "/>" Always Check your XML warning for any InflateClassException
Layout Resource file should only content elements and attributes.Any
XML text content found in file is likely accidental.
(From the warning message that represents the chance of crash.)
2. Remove Numbers form Id as ids are typically assigned in the layout XML file as a string.