I searched a ton in the internet on how to make my background image full on my android app and apparently it's still smaller. I was hoping if you guys know any solution for this?
Most of the image I've uploaded is on the #mipmap folder and apparently I can't find a way to insert an image in #drawable folder. I tried opening the drawable folder and copy paste a picture to put it inside but when it ran it came across a couple of errors.
Error:(12, 25) No resource found that matches the given name (at 'background' with value '#drawable/images').
This a picture of is how it looks like
I've also attached my content xml file:
<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
android:layout_height="fill_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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/activity_sad"
tools:context="com.example.chadymaebarinan.emojiexpress.Sad">
<ImageView
android:layout_width="150dp"
android:layout_height="150dp"
android:src="#mipmap/ic_launchersad"
android:gravity="center"
android:id="#+id/imageView"
android:scaleType="fitXY"
android:layout_marginTop="43dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="''I am SAD''"
android:textColor="#FFFF00"
android:textSize="50dp"
android:textStyle="bold"
android:gravity="center"
android:id="#+id/textView4"
android:layout_below="#+id/imageView"
android:layout_alignParentStart="true" />
<ImageButton
android:layout_width="111dp"
android:layout_height="111dp"
android:src="#mipmap/ic_launcherspeak"
android:background="#null"
android:scaleType="fitXY"
android:id="#+id/imageButton"
android:layout_below="#+id/textView4"
android:layout_centerHorizontal="true" />
<ImageButton android:id="#+id/back"
android:layout_width="111dp"
android:layout_height="111dp"
android:src="#mipmap/ic_launcherback"
android:background="#null"
android:scaleType="fitXY"
android:layout_below="#+id/imageButton"
android:layout_alignStart="#+id/imageButton" />
</RelativeLayout>
and here is my activity xml file:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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:fitsSystemWindows="true"
tools:context="com.example.chadymaebarinan.emojiexpress.Sad"
android:background="#drawable/ic_launcherimage">
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="#style/AppTheme.AppBarOverlay">
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_sad" />
</android.support.design.widget.CoordinatorLayout>
Put this into drawable folder instead of mipmap . The mipmap folders are for placing your app icons in only.
Drawable folders in res folder?
The image you want to add into your project just copy that and then right click on the drawable folder and press paste. I know you said you couldn't do it but that's how it works for me.
Once it is in the drawable folder you can set it as the background of your parent layout ie LinearLayout etc.
The mipmap is just for icons :)
put the my content.xml file into drawable folder and use it .
Related
While loading image in ImageView for Android Studio using android:src="#mipmap/stunner my image is getting blurred out, What to do?? Please help...
My code is as follows:
<ImageView
android:src="#mipmap/stunner"
android:adjustViewBounds="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="2dp"/>
Please use it as a drawable rather than using it as a mipmap. Mipmap is used for app icons but not for drawables
Here is the code and output with drawable
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/archive_task_open_btn"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:adjustViewBounds="true"
android:src="#drawable/bg" />
</FrameLayout>
An image I use (.jpg) in my Android Project is shown in the "Design" but when I start an emulator, it is not there. Other images are also not loaded.
I found some possible solutions Image showing in Android Studio but not on phone but none of the solutions worked in my case. To sum up, I tried:
moving image to a drawable-xxhdpi or mipmap--xxhdpi
using other image and also a different format (.png)
adding android:adjustViewBounds="true"
clean/rebuild project etc
No success. I work on OS X
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"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/background_light">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="#drawable/testimage"
android:id="#+id/imageView"
/>
<TextView
android:text="test"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView2"
android:textAlignment="center" />
</LinearLayout>
</RelativeLayout>
Image is showing in studio but not in Phone.
Image is placed in res.
Running on one plus one.
using linear layout
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="#drawable/wifi"
android:id="#+id/imageView3"
android:layout_centerHorizontal="true"
/>
You have to add below line in to your root layout.
xmlns:app="http://schemas.android.com/apk/res-auto"
Please see below example.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="#color/white"
android:clickable="true"
android:orientation="vertical">
<ImageView
app:srcCompat="#drawable/ic_user_red"
android:layout_width="50dp"
android:layout_height="50dp"/>
</LinearLayout>
without xmlns:app="http://schemas.android.com/apk/res-auto" you can not use app:srcCompat.
Inside res folder there like drawable,drawable-ldpi,drawable-mdpi,drawable-hdpi,drawable-xhdpi etc.
You should make sure that you copied your image in drawable folder not in Idpi or mdpi
try it by Changing the code to
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/wifi"
android:id="#+id/imageView3"
android:layout_centerHorizontal="true"
/>
A colleague of mine created for me a few pngs to enter inside a main menu. The pngs are suppose to be scaled to the right size like this:
I entered all the pngs in order to fit the hdpi xhdpi etc.,but when I put the "One player game" and "two player game" the images shrink and do not fit the size of the "Exit" button:
I tried all the variations of "android:scaleType" following this question. Also I tried padding (through a diff question that I can't find now). These resolutions did not help me.
I will be happy if you will be able to show me how to scale up these texts that are inside the png.
Here is my xml 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:background="#color/colorBackground"
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:layoutDirection="ltr"
tools:context="com.inbaltako.tictactoe.MenuActivity">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/logo"
android:paddingTop="50dp"
android:id="#+id/imageView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:id="#+id/relativeLayout">
</RelativeLayout>
<ImageButton
android:id="#+id/exitBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/exit_btn"
android:background="#color/colorPrimary"
android:padding="16dp"
android:onClick="btnClicked"
android:layout_marginTop="2dp"
android:layout_below="#+id/two_player_game"
android:layout_toStartOf="#+id/relativeLayout" />
<ImageButton
android:id="#+id/one_player_game"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/one_player_game"
android:background="#color/colorPrimary"
android:onClick="btnClicked"
android:padding="16dp"
android:layout_below="#+id/relativeLayout"
android:layout_alignStart="#+id/two_player_game" />
<ImageButton
android:id="#+id/two_player_game"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="#drawable/two_players_game"
android:background="#color/colorPrimary"
android:onClick="btnClicked"
android:padding="16dp"
android:layout_below="#+id/relativeLayout"
android:layout_alignStart="#+id/exitBtn"
android:layout_marginTop="39dp" />
</RelativeLayout>
It's hard to know if you put your drawables I the right places.
But if it's just text, why aren't you using TextView? Should be much easier.
Dealing with images just for text isn't the right thing to do.
I'm trying to use some portions of my previous project in my new project but I have encountered with a strange problem. My new project renders the same layout differently from the previous project. Here is the layout.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center" >
<ImageView
android:id="#+id/id1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/image"
/>
</FrameLayout>
And here are the two different results:
Layouts are 100% same but in the first one, ImageView holds a larger space than the image. In the second one, ImageView wraps the image, no extra space around the image. I want to use second one but what am I missing?
Target sdk, min sdk etc. are all the same.
Thanks in advance.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center"
android:paddingRight="50dp"
android:paddingLeft="50dp">
<ImageView
android:id="#+id/id1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/image"
/>
</FrameLayout>
You may want to try this code above. Adjust the paddings as you want!
Try this:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/id1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:src="#drawable/image"/>
</FrameLayout>