I am trying to create a layout in Android Studio but the preview of the layout is not showing at all. There is no errour though.
How can i get it to work properly? I will add a screenshot.
Preview not loading the layout
Thanks in advance.
<?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:id="#+id/content_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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.diceout.MainActivity"
tools:showIn="#layout/activity_main">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Let's Play!" />
<Button
android:id="#+id/rollButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="155dp"
android:layout_marginStart="155dp"
android:layout_marginTop="25dp"
android:text="Roll" />
</RelativeLayout>
TextView
#ivan franken Could you post your #layout/activity_main Xml code. I saw this line tools:showIn:#layout/activity_main
in code on your content_main.xml. I tested it in my project and got similiar result to yours. But when I deleted it, it worked fine.
Related
I had my viewflipper working, flipping between two images. I messed around with sizes and long story short the app crashes now. I undid everything and tried putting it in again, and I can't get it to not crash anymore. Without the viewflipper it runs fine.
here is my content_main.xml
<?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:id="#+id/content_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"
android:background="#drawable/background"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.melanie.cskiosk.MainActivity"
tools:showIn="#layout/activity_main">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome!"
android:visibility="visible"
android:textColor="#android:color/background_dark"
android:textStyle="normal|bold" />
<ViewFlipper
android:id="#+id/viewflipper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoStart="true"
android:flipInterval="2000">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/woit_161013_0749" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/woit_161013_0761" />
</ViewFlipper>
</RelativeLayout>
Not sure what I'm doing wrong here. Like I said I had this working just fine a few hours ago
I am very new to android development and was in the process of trying to create my first process when I came across the build error with which the question is titled.
Here is my XML code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app= ""
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.austinc.clicker.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:id="#+id/textViewCount"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textSize="24dp" />
<Button
android:text="Reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/ButtonClick"
android:layout_alignLeft="#+id/ButtonClick"
android:layout_alignStart="#+id/ButtonClick"
android:layout_marginTop="61dp"
android:id="#+id/buttonReset" />
<Button
android:text="Click"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="55dp"
android:id="#+id/ButtonClick"
android:layout_below="#+id/textViewCount"
android:layout_centerHorizontal="true" />
</RelativeLayout>
From what I can infer by double clicking on the error, the problem has to do with the second line of code (the meaning of which I have no idea). Is this a quick fix, or have I made a mistake somewhere in editing some piece of code?
I also faced the same issue, searched for 15 minutes and found the solution, i modified first three lines in content_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/content_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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.user.demoapp.MainActivity"
tools:showIn="#layout/activity_main">
After updating to use the 23.3.1 support libraries, the Layout Editor does not render imageViews using the app:srcCompat attribute.
<?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"
android:background="?android:colorBackground"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="in.srain.demos.vector.MainActivity"
tools:showIn="#layout/activity_main">
<ImageView
android:id="#+id/vector_drawable_cpu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/vector_drawable_cpu"
/>
<ImageView
android:id="#+id/vector_drawable_cpu_ani"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#id/vector_drawable_cpu"
app:srcCompat="#drawable/animated_cpu"
/>
<TextView
android:id="#+id/status_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/vector_drawable_cpu"
android:layout_centerHorizontal="true"
android:padding="5dp"
android:textColor="?android:attr/textColorPrimary" />
</RelativeLayout>
Looks like this in the Layout Editor preview
Has anyone figured out how to fix this?
Android Studio doesnt support app:srcCompat attribute, but you can add secondary tools:src="#drawable/animated_cpu" attribute to help IDE render your ImageViews in preview and layout editor. Then your ImageView looks like this:
<ImageView
android:id="#+id/vector_drawable_cpu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/vector_drawable_cpu"
tools:src="#drawable/animated_cpu"/>
I'm trying to set the profilepictureview in my app:
<RelativeLayout 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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="fr.djey.testf.MainFragment"
xmlns:facebook="http://schemas.android.com/apk/res-auto">
<com.facebook.login.widget.ProfilePictureView
android:id="#+id/facebook_avatar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/login_button"
android:layout_centerHorizontal="true"
/>
<com.facebook.login.widget.LoginButton
android:id="#+id/login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginBottom="30dp"
android:layout_centerInParent="true"/>
</RelativeLayout>
And I want to set the small size for the picture. I've found on internet that I have to put facebook:preset_size=small but it seems to don't exist anymore.
Can you tell me if there is another way to do this in xml (and not in java)?
It has been replaced with:
facebook:com_facebook_preset_size="small"
in parent layout add:
xmlns:facebook="http://schemas.android.com/apk/res-auto"
It is described in upgrade guide:
https://developers.facebook.com/docs/android/upgrading-4.x
--> Upgrading the Android SDK from 4.0.1 to 4.1.0
I am unable to see the image of the Image button when the image is in relative layout. If i use a different layout, image is working fine.
My layout is as follows:
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin">
<android.support.v7.widget.RecyclerView
android:id="#+id/cardList"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<ImageButton
android:layout_width="56dp"
android:layout_height="56dp"
android:src="#drawable/plus"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:id="#+id/fab"
android:elevation="1dp"
/>
</RelativeLayout>
the same image if i set in some other layout things work fine. Can any one give me some pointers where to look out.
There are no error or warnings in the log.
The actual png image is as follows:
If you want to implement floating button, the better way will be using existing library:
Add this line on your build.gradle dependencises:
compile 'com.getbase:floatingactionbutton:1.3.0'
And change your layout to:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin">
<android.support.v7.widget.RecyclerView
android:id="#+id/cardList"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<com.getbase.floatingactionbutton.AddFloatingActionButton
android:id="#+id/common_ring_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="10dp"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"/>
</RelativeLayout>
if you want to customise your floating button for example change colour, add this line as RelativeLayout attribute :
xmlns:fab="http://schemas.android.com/apk/res-auto"
and add the attribute below to the AddFloatingActionButton xml
fab:fab_colorNormal="#color/floating_button_bg"
fab:fab_colorPressed="#color/floating_button_bg_pressed"