When I set 9.PNG image as RelativeLayout's background, all elements inside it gets shrunken to the middle. Here is the XML and the snapshot.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/bg"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Just a simple white text which does not show up"
android:textColor="#ffffff"
/>
</RelativeLayout>
If I change background to a color or a normal image, I get the text.
android:background="#drawable/bg2" //normal image
Can anyone explain why is this happening?
Did you define the content area of your nine-patch? Because it looks like the content area is the little pixel in the middle.
The content area is defined by the bottom and right sides of your nine patch. You can for example make it as big as your patch.
Related
My background image of view is making some weird margins i don't need. Here is the photo:
As you can see TextView is highlighted and the View (with blue background image) should wrap around that TextView, but it looks like TextView is making some margins.
Here's the XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="#color/white_as_stone">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/circle_user"
android:id="#+id/view_user"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginLeft="#dimen/view_margin_to_side"
android:layout_marginStart="#dimen/view_margin_to_side"
android:layout_marginTop="#dimen/side_margins"
android:layout_marginRight="#dimen/side_margins"
android:layout_marginEnd="#dimen/side_margins">
<!-- margins above have nothing to do with my problem -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="why y doing this?"
android:id="#+id/txt_user"
android:textColor="#color/white_as_stone">
</TextView>
</LinearLayout>
And this is my background image:
I don't have much experience with 9-patch drawables, i tried tweaking scale area, but it doesn't help. Any help is appreciated.
You need to increase the black lines at the bottom and right of your 9patch image. They define the available content area for the image.
I'm trying to use a 9 patch background around an image to add a shadow around it.
What I have done so far is the following layout:
<LinearLayout
android:id="#+id/film_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top"
android:background="#drawable/movie_shadow"
android:drawingCacheQuality="auto" >
<ImageView
android:id="#+id/img_avatar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerCrop"
android:src="#drawable/film_test" >
</ImageView>
</LinearLayout>
Whit the following "movie_shadow.9.png":
I defined the content area (right and bottom edge) to be the white rectangle.
But the result is not what I expect. The content area is not what I define and the ImaveView is larger than the content area set in the 9 patch.
You see the red circle on the screenshot?
Why does the ImageView do not respect the content area of 9.png image?
I have overloaded the getView method of listview to populate custom style of list item.
This is what currently it looks like:!!
Red color is to just show the background of listview item
Here I have used 3 controls: Imageview for image, 2 text views (one top, one bottom).
Problem here is the height of listview item is getting increased. I want two textviews over the image not above or below. To someextent I know the root cause of this problem but don't know how to fix it.
Here is the layout of listview item:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" >
<ImageView android:id="#+id/imgIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:scaleType="fitCenter"/>
<TextView android:id="#+id/txtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="top"
android:textStyle="bold"
android:textSize="20sp"
android:textColor="#FFFFFF"
android:layout_marginLeft="10dp"
android:layout_marginTop="2dp"
android:layout_alignLeft="#+id/imgIcon"
android:layout_alignTop="#+id/imgIcon"
android:layout_alignBottom="#+id/imgIcon"/>
<TextView android:id="#+id/txtTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom"
android:textStyle="bold"
android:textSize="18sp"
android:textColor="#FFFFFF"
android:layout_marginLeft="10dp"
android:layout_marginBottom="5dp"
android:layout_alignLeft="#+id/imgIcon"
android:layout_alignTop="#+id/imgIcon"
android:layout_alignBottom="#+id/imgIcon"/>
The problem is i'm using png image for Imageview and their size is getting increased in some aspect ratio. In case I hard code the height of listview item layout then, specifically on my phone screen size, things start appearing good but on some different screen size things get totally worse (which makes sense too).
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="70dp"
android:padding="5dp" >
Would be great if someone can explain about how to do it. Main problem is to display text over an image (and image is not same). Thanks.
Update: My major problem is I don't have the bit vector of image instead a PNG and it tries to scale up the image. (setting scale type to center-fit could be an option but would it work on background resourcE?. Here is the output if I set image as a background for listview item and two texts over it.
Ok, when calling getView() in your CustomArrayAdaptor, rather than set the ImageView bitmap to the image you have (what you are currently doing, I believe), instead call View.setBackgroundResource(R.drawable.yourimage.png) on your view after you have infalted it. The equivalent in xml is below:
android:background="#drawable/yourimage".
If you need more information, let me know.
If you're using solid colors as the backgrounds, and you intend to support a variety of screen sizes, I would think it might be easier to use a background color fill on the text views, with the text views stacked and aligned such that there's no borders. Then it would not have any stacking issues (a simple Linear Layout would work) and it would be scalable with no processing of images.
This is my Android list_item layout XML:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:paddingRight="?android:attr/scrollbarSize"
android:background="#drawable/list_bg">
<TextView
android:id="#+id/tv_displayname"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:ellipsize="end"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
This is the list_bg image:
and yet here is what it looks like when shown in Android emulator:
I can see that the background is being applied because there is a slight gradient effect to it, but I have no idea where this black overlay is coming from!
have you tried a different image to see if that one does the same thing? to me it looks like it is creating the image behind the list in your RelativeLayout and your textview background is on top. since you are setting it to fill the width of the row, i bet if you just set to wrap_content you would see it behind there
try putting the image as your TextView background instead
I would like to place an image into the background of my activities. This image is effectively a circle shaped logo which will be semi-transparent, and should sit behind any other content on the UI. I will also offset it into the bottom corner.
What is the best way I can place this image without it become "squashed" (egg shaped) under varying screen dimensions? My app will operate in portrait mode only.
This is what I'm trying to achieve:
So far, I've placed my circle image onto 3 white rectangle canvases for the popular sized screens 480x854, 320x480 and 240x320 which seems to work, but I don't think its very solid.
Any tips?
This probably is not the perfect solution, and will require a bit of maintenance on the UI, but here's my thought:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_marginRight="-15dp"
android:layout_marginBottom="-15dp"
android:src="#drawable/circle"
/>
<!--Rest of Layout goes here-->
</FrameLayout>
Just wrap this around your current layout, and adjust the right and bottom margins to whatever negative margins you wish for the offsetting. This should work for any screen size, assuming you have drawables for each density.
EDIT: Yeah, you also shouldn't have to worry about a white rectangle this way, either. Just add the android:background tag to the FrameLayout with whatever color you want for the background, and save the logo as a transparent PNG.
I would do it like this, use a relative layout to have an ImageView in the background with on top of that a relative layout containing the rest of your layout
This way the image is as big as it can be keeping the correct dimensions
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:scaleType="centerInside"
android:src="#drawable/splash_picture"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<!-- rest of your layout -->
</LinearLayout>
</RelativeLayout>