Rendering xml file in Android Studio [closed] - java

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
This is my xml code in Android Studio. I am facing Rendering Problem in my Xml File.
<?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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.admin.myapp1.MainActivity1"
tools:showIn="#layout/activity_main1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:id="#+id/textView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Manab"
android:id="#+id/M_shaw"
android:layout_alignParentBottom="true"
android:layout_below="#+id/textView"
android:layout_alignStart="#+id/editText" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:layout_below="#+id/textView"
android:layout_marginTop="62dp"
android:layout_alignEnd="#+id/editText2" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/editText2"
android:layout_alignBottom="#+id/editText"
android:layout_toEndOf="#+id/textView"
android:text="45645" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Person1"
android:id="#+id/radioButton"
android:layout_below="#+id/editText"
android:layout_toEndOf="#+id/textView"
android:checked="true" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Person2"
android:id="#+id/radioButton2"
android:layout_below="#+id/radioButton"
android:layout_toEndOf="#+id/textView"
android:checked="false" />
</RelativeLayout>
error shown is-:
Exception raised during rendering: Binary XML file line #-1: Error inflating class
and also the error java.lang.NoSuchMethodError:
Help resolve this problem.

Seems that you have problem related to the Gradle cache.
Try the next step to "Refresh" your IDE (android studio)
1. Try Choose File | Invalidate Caches/Restart.

Related

ListView and SearchView bug [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
So I have a ListView in which I have filled random values. I also have a SearchView above the ListView. Whenever I click the SearchView, the Listview goes up. I do not want the Listview to be moved from its place. I am attaching two images for reference.
This is when the searchview is not active
This is when the searchview is active
Edit:: On emulator it works fine
CODE::`
<?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=".MainActivity">
<ImageView
android:id="#+id/NavigationBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="17dp"
android:adjustViewBounds="true"
android:padding="7dp"
android:src="#drawable/navigation_bar" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginStart="65dp"
android:layout_marginLeft="65dp"
android:layout_marginTop="17dp"
android:fontFamily="#font/product_sans_bold"
android:text="Library"
android:textColor="#color/green"
android:textSize="39sp" />
<ListView
android:id="#+id/ListView"
android:layout_width="match_parent"
android:layout_height="649dp"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:layout_marginStart="0dp"
android:layout_marginBottom="0dp"
android:divider="#null" />
<androidx.appcompat.widget.SearchView
android:layout_width="362dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="76dp"
android:background="#drawable/search_background"
app:iconifiedByDefault="false"
app:queryBackground="#android:color/transparent"
app:queryHint="Search music"
app:searchHintIcon="#null"
app:searchIcon="#drawable/search" />
</RelativeLayout>
`
NOTE: I HAVE A CUSTOM LISTVIEW IN WHICH I AM FILLING VALUES. I HAVE NOT IMPLEMENTED SEARCHVIEW CODE TILL NOW.
Adding these lines of code solved the problem.
Hope this may help some coder.
android:focusableInTouchMode="false" android:isScrollContainer="false"

How do I make this menu design in android xml? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 1 year ago.
Improve this question
view image
Is there some sort of library to do this or I have to go through using the card view or linear layouts?
Also does it have a name?
I made a cardView for you, buddy. You only need to change the drawables The Code below is what you see in this image:
<?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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#22ad80">
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
app:cardCornerRadius="10dp"
app:cardElevation="5dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/bank_frame"
android:layout_margin="5dp">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:src="#drawable/more"
android:id="#+id/bank_image"
android:layout_margin="5dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bank/Card settings"
android:id="#+id/bank_text"
android:layout_toEndOf="#id/bank_image"
android:layout_centerVertical="true"
android:layout_margin="5dp"
android:textColor="#000000"/>
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:src="#drawable/ic_arrow_right"
android:layout_toEndOf="#id/bank_image"
android:layout_marginStart="250dp"
android:layout_marginEnd="5dp"
android:layout_centerVertical="true"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/security_frame"
android:layout_below="#+id/bank_frame"
android:layout_margin="5dp">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:src="#drawable/more"
android:id="#+id/security_image"
android:layout_margin="5dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="My Security"
android:id="#+id/security_text"
android:layout_toEndOf="#id/security_image"
android:layout_centerVertical="true"
android:layout_margin="5dp"
android:textColor="#000000"/>
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:src="#drawable/ic_arrow_right"
android:layout_toEndOf="#id/security_image"
android:layout_marginStart="250dp"
android:layout_marginEnd="5dp"
android:layout_centerVertical="true"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/added_frame"
android:layout_below="#+id/security_frame"
android:layout_margin="5dp">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:src="#drawable/more"
android:id="#+id/added_image"
android:layout_margin="5dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BVN Added"
android:id="#+id/added_text"
android:layout_toEndOf="#id/added_image"
android:layout_centerVertical="true"
android:layout_margin="5dp"
android:textColor="#000000"/>
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:src="#drawable/ic_arrow_right"
android:layout_toEndOf="#id/added_image"
android:layout_marginStart="250dp"
android:layout_marginEnd="5dp"
android:layout_centerVertical="true"/>
</RelativeLayout>
</RelativeLayout>
</androidx.cardview.widget.CardView>
</RelativeLayout>

No bugs in Java or XML code, but app crashes on launch

I'm building a project app from a course. It ran and launched successfully in the previous version but after I copy pasted some code by the instructor in the earthquake_list_item.xml file , the app refused to launch both on the emulator and the physical device. There are no visible redlined errors or bugs that Android Studio shows me. I have checked the logcat and there are tons of errors, none of which I am able to understand. Please help.
This is the earthquake_list_item.xml file:
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingEnd="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingStart="16dp">
<TextView
android:id="#+id/magnitude"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center_vertical"
android:background="#drawable/magnitude_circle"
android:fontFamily="sans-serif-medium"
android:gravity="center"
android:textColor="#android:color/white"
android:textSize="16sp"
tools:text="8.9" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/location_offset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:fontFamily="sans-serif-medium"
android:maxLines="1"
android:textAllCaps="true"
android:textColor="#color/textColorEarthquakeDetails"
android:textSize="12sp"
tools:text="30km S of" />
<TextView
android:id="#+id/primary_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:textColor="#color/textColorEarthquakeLocation"
android:textSize="16sp"
tools:text="Long placeholder location that should wrap to more than 2 lines of text" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:orientation="vertical">
<TextView
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:textColor="#color/textColorEarthquakeDetails"
android:textSize="12sp"
tools:text="Mar 6, 2010" />
<TextView
android:id="#+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:textColor="#color/textColorEarthquakeDetails"
android:textSize="12sp"
tools:text="3:00 PM" />
</LinearLayout>
</LinearLayout>
These are some of the errors in the logcat:
java.lang.IllegalArgumentException: Context must contain application context.
at com.miui.analytics.internal.policy.h.<init>(SourceFile:7)
at com.miui.analytics.internal.policy.h.a(SourceFile:5)
at com.miui.analytics.AnalyticsCore.getClientExtra(SourceFile:2)
at com.miui.analytics.internal.util.g.b(SourceFile:2)
at com.miui.analytics.internal.util.g.a(SourceFile:4)
at com.miui.analytics.internal.LogEvent.a(SourceFile:40)
at com.miui.analytics.internal.LogEvent.<init>(SourceFile:42)
at com.miui.analytics.internal.collection.a.b(SourceFile:15)
at com.miui.analytics.internal.ApkReceiver$1.run(SourceFile:6)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:919)
Edit: I have found the problem and the solution, it was due to an xml file where I used selector instead of shape. Thank you to everyone who tried to help!
You should initialize the context variable in your onCreate for the main activity at least, try this in your onCreate method of the launcher activity context = activityName.this;

How to make a Login layout similar to this reference? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am creating an application in which I want to make a login screen similar to this. Kindly suggest the design of the last part of social media login.
Create a xml file like this for social media login part
=======
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/blue"
android:gravity="center"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="18dp">
<LinearLayout
android:id="#+id/social_icons"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginEnd="18dp"
android:layout_marginStart="18dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:background="#drawable/rounded_corners"
android:gravity="center"
android:padding="15dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:contentDescription="#null"
android:src="#drawable/google_plus" />
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginStart="24dp"
android:contentDescription="#null"
android:src="#drawable/google_plus" />
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:contentDescription="#null"
android:layout_marginStart="24dp"
android:src="#drawable/google_plus" />
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/blue"
android:textColor="#color/white"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:paddingStart="12dp"
android:paddingEnd="12dp"
android:layout_centerHorizontal="true"
android:text="Login With"/>
</RelativeLayout>
</LinearLayout>

Constraint errors in Java Android Studio

I could only find one thread pertaining to this and the answers didn't help fix the error. I am using a fresh install of Android Studio on a new laptop if that matters (maybe I need to install something that isn't currently there).
Error: This view is not constrained, it only has design time positions, so it will jump to (0,0) unless you add constraints
Edit2: It seems the new version of Android Studio doesn't use relative layout? I've tried manually changing the code as per this thread (How to switch from the default ConstraintLayout to RelativeLayout in Android Studio 2.3.3). Still not working.
Edit:
Here is an example of the code from a previous project (as you can see, this is different from my actual current code):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.squirreloverlord.ccarringtonphonephotoprint.MainActivity">
Below is my code for the main activity that is giving me the above error x4 (button/textView x2/radiogroup).
<?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:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.mercenaryferret.ccarrington1_currency.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/app_title"
android:textSize="24sp"
android:textStyle="bold|italic"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.032" />
<EditText
android:id="#+id/editText_usd"
android:layout_width="350dp"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/us_label"
android:inputType="numberDecimal"
android:textAlignment="center"
android:textSize="12sp"
tools:layout_editor_absoluteX="17dp"
tools:layout_editor_absoluteY="69dp"
/>
<RadioGroup
android:id="#+id/radioGrp"
android:layout_width="213dp"
android:layout_height="100dp"
tools:layout_editor_absoluteX="86dp"
tools:layout_editor_absoluteY="122dp"
>
<RadioButton
android:id="#+id/radioButtonEuro"
android:layout_width="98dp"
android:layout_height="wrap_content"
android:text="#string/euro_label"
tools:layout_editor_absoluteX="110dp"
tools:layout_editor_absoluteY="203dp" />
<RadioButton
android:id="#+id/radioButtonCanada"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/canada_label" />
<RadioButton
android:id="#+id/radioButtonMexico"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/mex_label" />
</RadioGroup>
<Button
android:id="#+id/buttonConvert"
android:layout_width="368dp"
android:layout_height="wrap_content"
android:text="#string/convert_label"
android:textAlignment="center"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="248dp" />
<TextView
android:id="#+id/textViewResults"
android:layout_width="316dp"
android:layout_height="31dp"
tools:layout_editor_absoluteX="34dp"
tools:layout_editor_absoluteY="354dp"
/>
Thank you in advance.
First of all at component tree there is ConstraintLayout left click on it and popup list opens then follow this :-
Constraint Layout >> clear all constraints then
Constraint Layout >> Add Infer Constraints
You need to add some missing constraints, here is how to do that.
Go to the Design View
Right click on your Widget
Click "Constraint Layout"
Click "Infer Constraint"
If above does not work, try below.
Go to the Design View
Right click on your Widget
Clear All Constraints
Click "Constraint Layout"
Click "Infer Constraint"
When you are using ConstraintLayout you must constraint your views both vertically and horizontally or else they may jump to the corner of your screen at run time.
After you constraint, your views as I said it will be placed according to your constraint and be relative to your screen - and your views won't jump in runtime.
Example to this layout using constraintLayout:
<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">
<TextView
android:id="#+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:text="app_title"
android:textSize="24sp"
android:textStyle="bold|italic"
app:layout_constraintBottom_toTopOf="#+id/editText_usd"
app:layout_constraintEnd_toStartOf="#+id/guideline4"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="#+id/guideline3"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.032" />
<EditText
android:id="#+id/editText_usd"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:hint="us_label"
android:inputType="numberDecimal"
android:textAlignment="center"
android:textSize="12sp"
app:layout_constraintBottom_toTopOf="#+id/radioGrp"
app:layout_constraintEnd_toStartOf="#+id/guideline4"
app:layout_constraintStart_toStartOf="#+id/guideline3"
app:layout_constraintTop_toBottomOf="#+id/textView8" />
<RadioGroup
android:id="#+id/radioGrp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintBottom_toTopOf="#+id/buttonConvert"
app:layout_constraintEnd_toStartOf="#+id/guideline4"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="#+id/guideline3"
app:layout_constraintTop_toBottomOf="#+id/editText_usd">
<RadioButton
android:id="#+id/radioButtonEuro"
android:layout_width="98dp"
android:layout_height="wrap_content"
android:text="euro_label" />
<RadioButton
android:id="#+id/radioButtonCanada"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="canada_label" />
<RadioButton
android:id="#+id/radioButtonMexico"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="mex_label" />
</RadioGroup>
<Button
android:id="#+id/buttonConvert"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="convert_label"
android:textAlignment="center"
app:layout_constraintBottom_toTopOf="#+id/textViewResults"
app:layout_constraintEnd_toEndOf="#+id/editText_usd"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="#+id/editText_usd"
app:layout_constraintTop_toBottomOf="#+id/radioGrp" />
<TextView
android:id="#+id/textViewResults"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:text="some text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="#+id/buttonConvert"
app:layout_constraintStart_toStartOf="#+id/buttonConvert"
app:layout_constraintTop_toBottomOf="#+id/buttonConvert" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.05" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.95" />
</androidx.constraintlayout.widget.ConstraintLayout>

Categories

Resources