The image I'm setting in the app is disappearing. Here is the layout XML file:
<TextView
android:id="#id/txt_colorText2"
android:layout_width="wrap_content"
android:layout_height="30.0dip"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#id/txt_colorText1"
android:text="#string/str_textColor2"
android:textColor="#0077dd"
android:textSize="18sp" />
<ImageView
android:id="#id/img_imgColorPreview"
android:layout_width="wrap_content"
android:layout_height="30.0dip"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#id/txt_colorText2"
android:background="#drawable/ic_launcher"
android:contentDescription="#string/str_imgColor" />
And here's the code. I do this in onTouch() method:
imgView_ImagePreview.setBackgroundColor(rgbCode);
Initially when the activity is started, ic_launcher icon is shown to the right of txt_colorText2. However on touching any part of the image, there is no content shown to the right of txt_colorText2.
I've debugged quite a lot, and haven't found the root cause. Any help is greatly appreciated.
By changing background color, you are changing the background itself. in the xml instead of setting background, set src to achieve what you want.
<ImageView
android:id="#id/img_imgColorPreview"
android:layout_width="wrap_content"
android:layout_height="30.0dip"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#id/txt_colorText2"
android:src="#drawable/ic_launcher"
android:contentDescription="#string/str_imgColor" />
Related
I want to put png image over button i tried android:background but the png takes all the button what i want exactly is to use the logo png over button like this
the info logo is my png and "about" comes from the button text
u can use this:
android:drawableTop="#drawable/SomeIcon"
so then you get this:
<Button
android:id="#+id/damage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="about"
android:drawableTop="#android:drawable/ic_menu_info_details"/>
it works for me :)
You can use a FrameLayout. In a FrameLayout, the z-index is defined by the order in which the items are added, for example
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_text" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/my_drawable"
android:scaleType="fitCenter"/>
</FrameLayout>
In this instance, the ImageView would be drawn on top of the Button, along the bottom center of the Button.
You can check this thread
Basically, you can use:
<ImageButton
android:id="#+id/ImageButton01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/album_icon"
android:background="#drawable/round_button" />
As the thread says.
Take a RelativeLayout, place ImageView inside it. Now set onClickListener on RelativeLayout.
By this way you can create more complex buttons.
<RelativeLayout android:id="#+id/your_btn_id"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" />
</RelativeLayout>
you can use
android:drawableTop
to put drawable at top of Button and use appropriate padding to make it position well.
<Buttton
android:layout_width="99dp"
android:layout_height="99dp"
android:background = "#drawable/bg" />
bg is your custom image.
i wish to adjust icons in my application that i'm about to devolp.
this is the link of the tutorial that i'm folowing .
"https://www.youtube.com/watch?v=lkadcYQ6SuY"
this is the example given and created in the tutorial .
now i don't have the reputation yet to post pictures to show you what i want BUT
simple i want arrows for back and forward (custom created) instead of textbuttons
anyone who can help me ... ?
You can use ImageButton, put your icon into drawable folder(if it doesnt exist, create it), and set it to your imageButton
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/yourImgName" />
You can create a simple Button and set its Background for picture.
<Button
android:id="#+id/button"
android:background="#drawable/help"
android:contentDescription="#string/help"
android:gravity="bottom"
android:onClick="showHelp" />
Or you can create ImageButton :
<ImageButton
android:id="#+id/sync"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:contentDescription="#string/sync"
android:background="#android:color/transparent"
android:src="#drawable/sync" />
try the below code
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/your_image_name"/>
I have a 9-patch image and what I want to do is to use it to "seperate" the adMob ad from the app. I want to draw a light blue line exactly where the ad is.
This is the 9-patch:
I added it to layout as ImageView and this is the XML code:
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/adView"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:src="#drawable/ab_transparent_example" />
And this is the result:
But what I want to get is the 9-patch to take the size of the screen, to make a full blue line from left to right of the screen. I've never worked with 9-patch before, what am I doing wrong?
The diagram below is a pretty good visual explanation of what a 9-patch is. As for your specific problem, you should set the 9-patch as the background to the image.
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/adView"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:background="#drawable/ab_transparent_example" />
First you need to know is that 9-patch is image as any other, regarding layout placing it. The difference is in way 9- patch image scale.
In this situation, try to set layout_width to "fill_parrent" or "match_ parent"
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/adView"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:src="#drawable/ab_transparent_example" />
ALL,
I am developing an application on Android where I need to load an image from the web and present it to the user in a ListView along with some other stuff. So I made 2 XML files (for row and whole display), wrote code to get the image and wrote the appropriate adapter.
Here is what I have:
product_line.xml:
<ImageView
android:id="#+id/product_picture"
android:contentDescription="#string/product_picture"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/product_name"
android:layout_toRightOf="#id/product_picture"
android:layout_alignParentTop="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/product_price"
android:layout_below="#id/product_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:id="#+id/add_to_cart"
android:layout_below="#id/product_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/add_to_cart"
/>
Unfortunately, upon running the code I see that the view is much bigger than the downloaded image and so takes a lot of spaces despite the "wrap_content" settings.
Is it possible to somehow set the view dimensions to display everything properly?
Thank you.
[EDIT]
I found this: http://argillander.wordpress.com/2011/11/24/scale-image-into-imageview-then-resize-imageview-to-match-the-image/, but unfortunately it doesn't make any differences.
[/EDIT]
To scale down your image view use:
android:adjustViewBounds="true"
android:maxWidth="32dp" <!--set the width you wish to be -->
i am writing an application to control a robot
for controlling i need ( up, down , right, left ) keys
i used eclipse designer to create it but maybe it is not possible
i want to create something like this :
how can i create buttons like this in center of screen ?
is there a better way to create arrow keys on android ?
Here you go :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<View
android:id="#+id/view1"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/view1"
android:layout_centerHorizontal="true"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/view1"
android:layout_centerHorizontal="true"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/view1"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/view1"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
Of course, you can replace ImageView with anything else like an ImageButton.
Be sure, if you change the name of the first view, tu update the name in the 4 ImageView.
And be aware that the corners of each image are overlapping each other.
I suggest using ImageButtons and setting the background for each to a State List Drawable xml file. This will change the image between states(focused, pressed, etc).
The tricky part would be positioning each so that they orient themselves in this sort of "box" you have above.
Just create some PNGs of each button in their positions. Up button points up, left points left etc. Then use RelativeLayout to position them with respect to each other. You can also use Buttons as well