Image not properly displayed in framelayout - java

I am Using a imageview under framelayout . I applied a background image in image view but image cannot fully cover the screen. it appears in center. I want to fully cover the Screen ...
How can i achieve it?
Thanx in advance :-)
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="com.example.muhammad.maqalatlayout.jild_copy"
android:background="#color/Green">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#mipmap/brown_border1"
android:layout_margin="0dp"
android:layout_marginLeft="0dp"
android:layout_marginTop="0dp"
android:layout_marginRight="0dp"
android:layout_marginBottom="0dp"
android:layout_gravity="top|left|bottom|center_vertical|right"
android:visibility="visible"
android:adjustViewBounds="false"
android:scaleType="fitStart"/>
My Current output is like this.

I believe your scale isn't working because you are setting the android:background property. Try this:
<ImageView
...
android:src="#mipmap/brown_border1"
... />
Also, preferably put your image in the /drawable/ folder.

use
android:scaleType="fitXY" and `match_parent` instead of `fill_parent`.

Related

Drawing line between two drawables in the textviews

I have the issue with drawing line like in a pic above. How can I do that? Here's the code of the view, where I need to implement that. I guess I need to use canvas, but I'm not sure about that. Thanks for any advice!
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="#dimen/linear_layout_buttons_margin_top"
android:orientation="vertical">
<TextView
android:id="#+id/button_from_city"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="60dp"
android:layout_marginRight="60dp"
android:layout_marginTop="4dp"
android:background="#drawable/button_white"
android:drawableLeft="#drawable/ic_green"
android:drawablePadding="#dimen/dots_white_button_padding"
android:drawableStart="#drawable/ic_green"
android:gravity="center_vertical"
android:hint="#string/from_place"
android:padding="#dimen/dots_white_button_padding"
android:textColor="#color/color_accent"
android:textColorHint="#color/text_view_hint_color"/>
<TextView
android:id="#+id/button_to_city"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/button_from_city"
android:layout_marginBottom="4dp"
android:layout_marginLeft="60dp"
android:layout_marginRight="60dp"
android:layout_marginTop="4dp"
android:background="#drawable/button_white"
android:drawableLeft="#drawable/ic_red"
android:drawablePadding="#dimen/dots_white_button_padding"
android:drawableStart="#drawable/ic_red"
android:gravity="center_vertical"
android:hint="#string/to_place"
android:padding="#dimen/dots_white_button_padding"
android:textColor="#color/color_accent"
android:textColorHint="#color/text_view_hint_color"/>
</RelativeLayout>
You can provide two drawable resources for the textviews and set them as drawableStart, based on the required conditions of your work. The point here is using an image which contains a colored circle and a line, which is much simpler than drawing the layout with canvas.
I will simply add two View with grey background of 1dp width above and below your dot drawable and manage visibility depending on the position of your items.

How can I correctly put an image at the top of an ImageView having a specified height?

I am absolutly a beginner in Android development and I have some problem positioning an image into an ImageView element of my layout. So I have the following situation, I have this fragment layout:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Dummy content. -->
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="0dp">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:scaleType="fitCenter"
android:layout_height="350dp"
android:src="#drawable/carbonara"/>
<!--android:background="#drawable/carbonara" />-->
<TextView android:id="#android:id/text1"
style="?android:textAppearanceLarge"
android:textStyle="bold"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp" />
</LinearLayout>
</ScrollView>
So, as you can see in the previous code snippet I am setting a background image into an ImageView having an height of 350dp setted.
The problem is that the image height is less that 350dp and this is what I am obtaining:
As you can see in the previous screenshot what I obtain is that I have the 350dp ImageView (highlighted in blue) and the image is setted inside it vertically centered. I don't want that the setted image is vertically centerd but I want that it start at the top of the ImageView.
How can I implement this behavior? What am I missing?
I have tryed to change:
android:src="#drawable/carbonara"/>
with:
android:background="#drawable/carbonara" />
and in this way it fills all the ImageView space but in this way the image could appear deformed so I think that it is not a good solution.
try to change in your layout and test again.
android:scaleType="fitCenter"
to
android:scaleType="fitStart"
See full docs here

Android ImageView scale type centerCrop

I'm creating an activity on Android. I want to show a background image in it. I put a ImageView into my main RelativeLayout.
<RelativeLayout
android:id="#+id/relativeLayoutMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:orientation="vertical" >
<ImageView
android:id="#+id/bgImage"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:src="#drawable/bg4"
android:scaleType="centerCrop" />
</RelativeLayout>
It makes view like this.
I need to make view like this
How can I do it?
Try set ImageView attribute ScaleType=fitEnd ?
use this code.it's give the out-put as you want.
Code
<?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="match_parent" >
<RelativeLayout
android:id="#+id/relativeLayoutMain"
android:layout_width="150dp"
android:background="#android:color/background_dark"
android:layout_height="150dp" >
<ImageView
android:id="#+id/bgImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:scaleType="centerCrop"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
</RelativeLayout>
one advice if u give the imageview width fill parent then it's contain whole space according to main container.
Best Luck
Set the android:background="#drawable/bg4" in the RelativeLayout like that:
The whole XML should look like that:
<RelativeLayout
android:id="#+id/relativeLayoutMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:background="#drawable/bg4
android:orientation="vertical" >
</RelativeLayout>
First, I believe there are a couple of things wrong in the xml:
RelativeLayout does not make use of an orientation, you should remove that
Is this your full xml file? If so then the alignParentLeft in the RelativeLayout doesn't do anything because that is an attribute you use if it's parent is a RelativeLayout.
fill_parent is the deprecated name of match_parent, you should use that.
I also believe that code you have would center the image on the screen putting anything that is to big evenly on both sides and not at all what you said it does.
If you just want a background you can just use android:background="#drawable/bg4" in the RelativeLayout
EDIT: Changing the layoutparams of the ImageView to wrap_content both height and width and removing the scaleType alltogether might make it like you wanted it to be.

How can I set the imageview to take up the width of the screen?

I would like an imagview that takes up the width of the screen (or layout) but there seems to be padding around the view that prevents me from doing this.
With the corresponding xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent" android:weightSum="1">
<ImageView android:src="#drawable/icon" android:background="#null"
android:layout_height="106dp" android:id="#+id/imageView1"
android:layout_weight="0.59" android:layout_width="match_parent"></ImageView>
</LinearLayout>
The padding is come from transparent area on android icon.
Just remove unused transparent area or use another image.
Try changing:
android:layout_width="match_parent"
to:
android:layout_width="fill_parent"
make layout width and height as fill_parent
<ImageView android:src="#drawable/icon" android:background="#null"
android:layout_height="fill_parent" android:id="#+id/imageView1"
android:layout_weight="1" android:layout_width="fill_parent"></ImageView>

How to place a text between two images in Android

I want to create layout where I have two images at left and at right and text in center.
I have tried to do it with relative layout but unfortunetly it was unsuccessfully. Could anybody provide me an example?
Have you tried something like?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/img1"
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_alignParentLeft="true"
android:src="#drawable/image1"/>
<ImageView
android:id="#+id/img2"
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_alignParentRight="true"
android:src="#drawable/image2"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/img1"
android:layout_toLeftOf="#id/img2"
android:layout_alignTop="#id/img1"
android:text="I'm between!"/>
</RelativeLayout>
If you don't need more things on your view, you could want to use LinearLayout instead, since it's more easier to implement. In that case, you just have to play with the layout_weight attribute.

Categories