How can I get ImageView to scale an image and align top right? - android-layout

I've spent 3 hours trying to get this to work without success so heopfully someone here can help.
I have a FrameLayout that is being loaded via inflate from an XML file and in it I have the following layout:
<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical" >
<ImageView
android:id="#+id/element_image"
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_weight="1"
android:layout_marginBottom="10dip"
android:layout_marginLeft="10dip"
android:scaleType="fitStart"
android:background="#888888" >
</ImageView>
<Button android:id="#+id/element_button"
style="#style/Button"
android:layout_gravity="right"
android:text="#string/element_button_label"
/>
</LinearLayout>
I have an image loaded from a BLOB which I want to display in this ImageView. In the GalleryAdaptor I load the image like this:
ImageView image = (ImageView) v.findViewById(R.id.element_image);
byte [] bitmapData = cursor.getBlob(4);
Bitmap bitmap = BitmapFactory.decodeByteArray(bitmapData, 0, bitmapData.length);
image.setImageBitmap(bitmap);
When I use android:scaleType="fitStart" in the layout above the image is not scaled to the height or width of the ImageView but is about a third of it's width (which I can see from the grey background I have given it) and is centered.
If I use android:scaleType="fitXY" the image height is scaled but the width is not. Again the image is centered.
Can someone give me some pointers on:
How to get the image to scale both height and width wise
How to align the image top right

Answering my own question here - but looks like this was just an issue with the source image resolution. Android (2.2 at least) does not seem to want to scale these images up when fitStart or fitEnd is used - but when fitXY is used it does scale them.

Related

image view not show when use on nine patch image in android

I am using nine patch image (shadow_15347) as a background for shadow and above it i am using image view with background or src of my logo png. my nine patch image show but my logo png not show when it run on emulator. while in design view of activity it shows properly please tell me where i am wrong thanks in advance.
<LinearLayout
android:layout_width="0dp"
android:layout_weight="0.2"
android:layout_height="match_parent"
android:gravity="center"
android:background="#drawable/shadow_15347"
android:orientation="vertical">
<ImageView
android:id="#+id/imageView5"
android:layout_width="300dp"
android:layout_height="300dp"
android:background="#drawable/ic_baseline_add" />
</LinearLayout>
in imageview why are using android:background tag to set your image, you could src tag and check.

Confuse about recyclerview and imageview sizes

i'm currently using a recyclerview to display a menu consisting of an image each row.
i've created the image to be 1080 x 300 in order so it can be scale down withouth mutch issue
I can't quit understand what width options to use for the RecyclerView, and for the items layouts and imageview.
I need the image view to be, around 150dp in Height and the With to ocupy the entire screen, just like on the editor
EDIT 1:
Now theres a huge empty space between rows
Use this code for ImageView in layout resource file created by yourself like custom.xml i.e. res/layout/custom.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imgItem"
android:layout_width="match_parent"
android:layout_height="150dp" />
</RelativeLayout>
Use this code for RecyclerView :
android:width="match_parent"
android:height="match_parent"
Try to change the Scale of Image View to Center Crop or Fit XY
Like This:
android:scaleType="centerCrop"
Use RecyclerView in your default activity like this
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible">
<ImageView
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:src= "" />
</androidx.recyclerview.widget.RecyclerView>
</RelativeLayout>
Note that the height for ImageView is wrap content. This will work fine given that the height of each image is equal

Adding Layout Weight dynamically

For my project I want 30 images in my page, and I want to arrange them in such a way that there are 3 images in one horizontal linear layout.
Since I cannot use density pixels as it may look different on different divices, I want to use layout_weights. The way we write in our XML files :
<ImageButton
android:id="#+id/my_image"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center"
**android:layout_weight="0.33"**
android:background="#android:color/transparent"
android:src="#drawable/ic_launcher" />
I want to know what will be the Exact Equivalent of the XML code in Java Language..
You can set the weight using the LayoutParams of your view (the last param)
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT, 1.0f);
myView.setLayoutParams(params);

what element type and layout for should I use for app landing page navigation buttons?

I'm pretty new to Android Development, i'm following some Youtube tutorials currently. I'd like to create a basic mobile tourist application, but i'm stuck as to how to create the main menu layout.
Each Favorite 1 - 3, and Options 1 - 9 should be icons. (I'm not sure which form element should be used for this).
QuestionHow can I create the favorite, and option icons in the layout.xml file, what element is best suited, and what layout(s) should I use?
In HTML, i'd create a table with 3 columns, 4 rows and set the table width and height to be 100%, and make the td valign and align central.
Here you could make horizontal linearLayouts of vertical LineraLayouts of Image+TextView pairs.
The second range linear layouts would have
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
Inside second range layouts you could use for image and text/view:
...for images:
android:layout_width="match_parent"
android:layout_weight="3"
android:layout_height="0dp"
... for texts
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp"
And the screen is nicely divided.

How To Remove The Black Lines On Layout Screen In Android?

I have frame layout in which I placed an image with 480x800 resolution to fill the screen. Now I am placing a button on to the image.
My XML looks like this....
<ImageView android:id="#+id/ImageView01"
android:layout_width="480px"
android:layout_height="800px"
android:src="#drawable/img">
</ImageView>
<FrameLayout android:id="#+id/FrameLayout01"
android:layout_width="174px"
android:layout_height="64px"
android:layout_gravity="bottom|right"
android:layout_marginBottom="40px"
android:layout_marginRight="16px">
<Button android:id="#+id/callend2"
android:layout_width="176px"
android:layout_height="64px"
android:paddingLeft="20px"
android:paddingRight="10px"
android:textColor="#f5f5f5"
android:textSize="24px"
android:background="#drawable/csh_call_red_btn_normal"
android:drawableLeft="#drawable/call_end_call_icon"
android:text="call end">
</Button>
</FrameLayout>
My problem is I am getting black line on the border of the Button or Inner Frame Layout...
It would help to know what kind of view contains the ImageView and FrameLayout.
But if you want an image for a background, why not just set the android:background attribute of the root view of your hierarchy?

Resources