Android Studio: ImageView not showing - java

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>

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>

CardView does not show elevation at run time

Here is the xml code :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/activity_main"
android:orientation="vertical"
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.himanshu.staticlogin.MainActivity"
android:weightSum="1">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
card_view:cardBackgroundColor="#color/cardview_dark_background"
card_view:cardElevation="10dp"
android:clickable="true"
/>
</LinearLayout>
It shows elevation in the preview but when I run the file it does not. What am I doing wrong?
set for cardview:
card_view:cardUseCompatPadding="true"
Use card_view:cardUseCompatPadding="true" in your xml to show elevation on pre Lollipop androids.

Background Image that fits the android studio project

When i applied an image to emulator on android studio, it gives an image without covering borders. Screen shot of this problem is as under, but what i get is to completely fill the emulator with my image.
XML code:
<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:background="#drawable/background_image"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MainActivity">
</RelativeLayout>
Your XML looks like :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
android:paddingBottom="16dp"" >
So the thing you've to do is remove the paddings from your XML, and if you have put the image correctly it will fit on your screen :)
EDIT1
<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:background="#drawable/background_image"
tools:context=".MainActivity">
</RelativeLayout>
EDIT2
<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:background="#drawable/background_image"
android:layout_centerInParent="true"
android:scaleType="centerCrop"
tools:context=".MainActivity">
</RelativeLayout>
EDIT3
Use this image instead : http://i.imgur.com/oqES1TU.jpg

Android splash screen not appearing correctly

When the app is loading, instead of a proper splash screen it just shows, the best way to describe it, when you go to install an app from the Play store, the black screen with the icon in the top left corner and some text, that's all it shows when launching my app...
I narrowed it down to activity_game.xml as when looking in the Graphical Layout of that file, it just shows a boring black screen with text.
How would I change this to incorporate a full screen image on splash instead?
Let's say for example, the image is called 'loading.png'
Content of activity_game.xml is below;
<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=".GameActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
</RelativeLayout>
--- Edit -
Thanks Rod, works to the point I now get a black screen on launch, I copied loading.png into the drawable folder and use the code like this;
<?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"
tools:context=".GameActivity" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/loading"
android:adjustViewBounds="true"
android:scaleType="fitXY" />
</RelativeLayout>
Not sure why it is not loading the image?
First you need to make your activity full screen by setting the theme to no title bar into your activity tag of the manifest and add this:
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
Dont add padding to the RelativeLayout to avoid the black screen border, instead of TextView use the ImageView to create an image to the layout.
sample:
<?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"
tools:context=".GameActivity" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="your_drawable_image"
android:adjustViewBounds="true"
android:scaleType="fitXY" />
</RelativeLayout>

Categories