Solution 1 :
Welcome to StackOverFlow !
If there is no special requirement than no need to use match_parent
inside ImageView. You can do following adjustment-
<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_layout_width="match_parent"
android_layout_height="match_parent"
android_orientation="vertical"
tools_context=".PokemonActivity">
..............
<ImageView
android_id="@+id/pokemon_avatar"
android_layout_gravity="center"
android_layout_width="wrap_content"
android_layout_height="wrap_content"/>
</LinearLayout>
Happy coding !
Solution 2 :
sorry. I was roasting snow in a furnace. I found out that actually source image is one to blame. Image size does not wrap the content but it has extra space around content. This is the reason when it is enlarged, there is space between text and image.
Problem :
I have been working on CS50 and now I am tracking android. I almost finished my PSet Pokedex, but small thing is bothering me.
I am trying to align bitmap image on top of ImageView, but I could not do it. Could you please help me? I tried “scaletype”, “layout_gravitiy” etc. But it does not seem to work. I want image to be just below description stating that this should be changed by the java code.
Please see current view here
<?xml version="1.0" encoding="utf-8"?>
<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_layout_width="match_parent"
android_layout_height="match_parent"
android_orientation="vertical"
tools_context=".PokemonActivity">
<TextView
android_layout_width="match_parent"
android_layout_height="wrap_content"
android_id="@+id/pokemon_name"
android_textAlignment="center"
android_textSize="18dp"
android_textStyle="bold"
android_paddingTop="10dp" />
<TextView
android_layout_width="match_parent"
android_layout_height="wrap_content"
android_id="@+id/pokemon_number"
android_textAlignment="center"
android_textSize="16dp"
android_paddingTop="5dp" />
<TextView
android_layout_width="match_parent"
android_layout_height="wrap_content"
android_id="@+id/pokemon_type1"
android_textAlignment="center"
android_textSize="16dp"
android_paddingTop="5dp" />
<TextView
android_layout_width="match_parent"
android_layout_height="wrap_content"
android_id="@+id/pokemon_type2"
android_textAlignment="center"
android_textSize="16dp"
android_paddingTop="5dp" />
<Button
android_id="@+id/pokemon_button_catch"
android_layout_width="match_parent"
android_layout_height="wrap_content"
android_textAlignment="center"
android_paddingTop="5dp"
android_textSize="24dp"
android_onClick="toggleCatch"
/>
<TextView
android_layout_width="match_parent"
android_layout_height="wrap_content"
android_id="@+id/pokemon_description"
android_textAlignment="center"
android_textSize="16dp"
android_textStyle="bold|italic"
android_paddingTop="50dp"
android_text="This is testing something, this should changed by the java code."/>
<ImageView
android_id="@+id/pokemon_avatar"
android_layout_width="match_parent"
android_layout_height="match_parent"/>
</LinearLayout>
Comments
Comment posted by Shubham Gupta
Use Relative layout to overlap views
Comment posted by Code Demon
Change scale type to fitxy then you can adjust the padding top as per your needs
Comment posted by enszrlu
fitxy is messing the scale of the image and seems to does not work. I could not solve with relative layout also.
Comment posted by Abdur Rehman
also send image that you are going to set in imageview
Comment posted by enszrlu
Thanks for the tip. But source image is soo small that I want to make it big as possible.