Cannot resolve dimensions in main_activity.xml - java

I'm following a tutorial to help me build a 2D game - https://www.simplifiedcoding.net/android-game-development-tutorial-1/#Planning-the-Game-Story
The tutorial tells me to add the following 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: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/splash"
tools:context="net.simplifiedcoding.simplegame.MainActivity">
But I'm getting cannot resolve errors on the following:
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
I've tried ALT+Enter to create a dimen.xml file, but I'm not sure what to even put when doing this and my app will not compile.

Do not have the dimen file
You must create one and place the data in your educational video
Or change the code to this:
android:paddingBottom="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
Put the number in the tutorial video you're following to get the correct numbers instead of the written number 0

Okay I figured it out, I hit ALT+ENTER to create a dimen.xml file, I then put the value as 0dp for each.

Related

How to remove full screen mode in android app

I am new in android app development I didn't declare anything for full screen mode still it asks in bottom of my application during runtime for full screen mode only for device with small screen like redmi 6A Here is output
Its just a demo app to ask for permission like call , contacts etc it works fine without crashing just i want to remove that option for full screen from bottom of the screen
would really be great full if anyone can guide
Thanks in advance
UPDATE
permission_layout.xml
<?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: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.android.dialer.PermissionActivity">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true">
</LinearLayout>
</RelativeLayout>

Android: Adding a VectorDrawable to an ImageView

So, I wanted to make a scroll-able worldmap with clickable countries. So when I found out there was a thing like VectorDrawables, I decided to give these a try.
Next thing I did was making a VectorDrawable xml file out of a SVG and tried to put it in my ImageView. While searching for some info, I found out that there were 101 ways to do this, and none of them worked for me...
The interesting thing is that, when I add "android:src="#raw/worldmap" in the ImageView in my activity.xml, the map shows up in the preview, but whenever I try to run the app, it crashes.
<LinearLayout
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:orientation="vertical"
android:id="#+id/activity_show_hint"
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.bert.myapplication.ShowHintActivity"
android:weightSum="1">
<ImageView
android:id="#+id/img"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:scaleType="center"
android:src="#raw/worldmap">
</ImageView>
</LinearLayout>
First, move your VectorDrawable to Drawable folder (not in raw). and then, add this line in your Gradle file :
defaultConfig{
vectorDrawables.useSupportLibrary = true
}
And finally, in your imageView, change to this;
<ImageView
android:id="#+id/img"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:scaleType="center"
app:srcCompat="#drawable/worldmap">
</ImageView>

Android Studio: ImageView not showing

I´m new in Java and Android Studio and tried to use a png in my test-application.
Since I own a AMD processor I have to use my real device (Galaxy S6) to run it. Strangely, the Image that I used shows up in Android Studio, plus it´s in the right size. Anyways, it´s not showing up on my device, theres only the white background.
Code: (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: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.chris.startbildschirm.MainActivity"
tools:showIn="#layout/activity_main">
<ImageView
android:layout_width="300dp"
android:layout_height="300dp"
android:id="#+id/imageView"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:src="#drawable/logo"/>
</RelativeLayout>

Android Emulator still showing Hello World

So I've set up my Eclipse to have the Android SDK and ADT plugin.
I set up my AVD to have a Galaxy Nexus and Galaxy S2 emulator.
I've created a new Android project and I get my blank MainActivity which simply displays "Hello World!" which is the problem.
In the Graphical Layout, I delete the "Hello World!" text to remove it. I check in the activity_main.xml and the script containing the "Hello World!" text is no longer there. I run in either emulator and everything works, but when the app opens, "Hello World!" is still there.
Here's the xml now
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.project.MainActivity"
tools:ignore="MergeRootFrame" />
I've changed nothing except removing that text. The MainActivity.java has not been touched. Is there something I'm missing?
This was a little bit odd when it happened to me, just remove the Hello World Text View from the fragment.xml file and it should be fine.
that xml code is just for layout when you add smthg on layout this code will be bigger,example
<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: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=".MainActivity" >
<Button
android:id="#+id/bb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/editText1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="72dp"
android:text="git" />
thats have only a button
your code has nothing only layout

Error parsing XML: unbound prefix Admob

I got a problem in my layout where Im trying to add the Admob.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads ="http://schemas.android.com/apk/lib/com.google.ads"
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="#drawable/lined2"
tools:context=".MainActivity" >
<com.google.ads.AdView
android:id ="#+id/adview"
android:layout_width="fillparent"
android:layout_height="wrap_content"
ads:adUnitId="My ID"
ad:adSize="BANNER"
ads:testdevices="TEST_EMULATOR"
ads:loadAdOnCreate="true" />
So the Error is in this line :
<com.google.ads.AdView
It says :
Error parsing XML:unbound prefix
I really searched many Posts but no one helped me...
I allready add the line with add xmlns:ads .... but It doesnt help :/
Did I forgot sth. ?
Thank you for your help !
You missed s in the namespace for adSize.
Change
ad:adSize="BANNER"
to
ads:adSize="BANNER"
<com.google.ads.AdView
android:id ="#+id/adview"
android:layout_width="fillparent"
android:layout_height="wrap_content"
ads:adUnitId="My ID"
**ads:adSize="BANNER"**
ads:testdevices="TEST_EMULATOR"
ads:loadAdOnCreate="true" />
correction.

Categories