I am developing an app based on client-server application. I am using tablelayout, and in tablelayout am adding some textview, edit text and image( for click ). My screenshot is as follows:
as you can see in my image add button blurs. It is just a 3kb file.
final ImageView img_add_icon = new ImageView(MainScreen.this);
img_add_icon.setBackgroundResource(R.drawable.add_item_order);
and my xml file is:
<ImageView
android:id="#+id/add_to_order_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2dip"/>
What can I do to stop the blurring of this image?
Please Use
setImageResource(resId)
to Sets a drawable as the content of this ImageView.
To Control how the image should be resized or moved to match the size of this ImageView
use
setScaleType(ImageView.ScaleType scaleType)
[1]: http://developer.android.com/reference/android/widget/ImageView.html#setImageResource%28int%29
[2]: http://developer.android.com/reference/android/widget/ImageView.html#setScaleType%28android.widget.ImageView.ScaleType%29
Related
I want to add an image background to my buttons (which are added dyncamilly), but the image original size looks applied by default, and it is far too big. How can I adjust my image to fit with the button size automatically ?
Drawable img = act.getResources().getDrawable(R.drawable.top);
button.setBackground(img);
Use an ImageButton http://developer.android.com/reference/android/widget/ImageButton.html
They should handle the sizing automatically
Inside your Button xml, try adding this
android:scaleType="fitCenter"
I have given the image view of certain size the image which i have smaller size than the image view when i fit the image view it is looking like the picture is at the corner but i would like to get the picture in certain pattern such as after filling the smaller image in the image view on the corner the remaining space of the image view should be filled with the same smaller pic until it fits the size of the image view.
Use android:scaleType="fitXY" and android:adjustViewBounds="true". This will work in your case.
Try this, Add scaleType attribute in your xml file
android:scaleType="fitXY"
In your layout file where the ImageView component is you can add this attribute
android:scaleType="fitXY"
In my new android app I need to give border to imageview by using something like .9.png.
The border size should change with respect to image which I have given to imageview and If possible I need to give a background image to imageview as I'm going to apply a transparent png image to imageview.
Should I create a new custom view for this?
I think you should create a custom view. Do a LinearLayout with the background as the border and have the ImageView centered inside the LinearLayout. Use 9-patch to get a correct stretch and create a content area so that the border is showing (use draw9patch in android SDK/Tools).
Example:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/border">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
</LinearLayout>
Then 9-patch your border (border.9.png in this example). You can have the same stretching as content area.
I have an ImageView that is 1x20px. The image is a .9.png. I am trying to use match_parent but when I run the app on my device, it is not stretched to fill the width of the screen. Here's the code in the XML for the ImageView
<ImageView
android:id="#+id/dividerBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/ic_bar"
android:layout_gravity="center_horizontal"
android:scaleType="centerInside" />
Any ideas on how I can get the ImageView to cover the entire width of the screen?
If it's a 9 patch it needs to be set as the background attribute of the imageview for it to scale properly. Right now it's trying to scale the image as it would any other image using the scaleType tag that you provided.
Try setting
android:background="#drawable/ic_bar"
and remove the src attribute
Additionally, if you are using the imageView only to display the 9-patch you can switch to using a regular View instead of the ImageView. As long as you set the background attribute you will be good to go.
I have an image which is 450px square below some text in a linear layout and wanted it to fill the width of the device, which I done by using;
ImageView android:id="#+id/my_image_container"
android:src="#drawable/my_image"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/orange"
android:scaleType="fitStart"
This has worked in a fashion, but the ImageView element fills the rest of the screen and any elements placed under do not show.
Does anyone know of a way to trim the bottom of the space that the ImageView uses.
Hopefully this image can explain it better - I want to crop the empty area under the image (orange background).
I recommend you to use a RelativeLayout instead of a LinearLayout. You can then use android:layout_above="" and android:layout_below="" to ensure that you get the layout you want.