Tag: layout

Android – Get ListView item height?

Is there a way to get ListViewItem height in code, when there is no actual items in list? My ListViewItem layout: <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”fill_parent” android:layout_height=”?android:attr/listPreferredItemHeight”> … </LinearLayout> I have tried to get it using Inflater: View convertView = LayoutInflater.from( this ) .inflate( R.layout.mail_list_row, null ); int itemHeight = convertView.getHeight(); But it’s return 0; Thanks!

Custom notification layout don't work on Android 2.3 or lower

I use the NotificationCompat.Builder to display my notification through android versions and use a custom layout for the notification. The custom layout works fine on Android 3 and up (API Level 11), but don’t show up on API Level 10 or lower. I tested it on 2.3 and 2.2 in the Emulator. Heres my code: […]

Opacity on a background Drawable image in View (using XML Layout)

I was just wondering if there was a way to change the opacity of the background image for a View (ie. TextView, etc.). I know that I can set the background image like this: android:background=”@drawable/my_drawable_image” Or I can set a specific background colour with an alpha setting like this: android:background=”#10f7f7f7″ Is there a way I […]

Android custom RatingBar image artifacts

I implemented a custom RatingBar in an application on my ListView items. Custom style ratingbar_red.xml: <?xml version=”1.0″ encoding=”UTF-8″?> <layer-list xmlns:android=”http://schemas.android.com/apk/res/android”> <item android:id=”@android:id/background” android:drawable=”@drawable/star_off” /> <item android:id=”@android:id/secondaryProgress” android:drawable=”@drawable/star_on” /> <item android:id=”@android:id/progress” android:drawable=”@drawable/star_on” /> </layer-list> Here’s part of ListItem layout: <LinearLayout android:layout_width=”fill_parent” android:layout_height=”wrap_content” android:orientation=”horizontal” android:paddingLeft=”15dp” > <RatingBar android:id=”@+id/li_company_rating” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_marginTop=”15dp” android:layout_marginBottom=”1dp” android:isIndicator=”true” android:numStars=”5″ android:progressDrawable=”@drawable/ratingbar_red” android:stepSize=”1″ /> […]

Setting Android TimePicker In XML

Is it possible to set TimePicker hours mode to 24-hours-mode in XML file? Or is it posible in Java only? I want to make a layout that has 24-hours picker but I can’t find such attribute.

Android: Add a view to a specific Layout from code

I want to dynamically add some views to a LinearLayout that is already defined in XML. I’m able to add views to the screen but they are not being placed ‘inside’ the right LinearLayout. How can I get a reference to this specific Layout from code, similar to getting a View by using findViewById()?

Error : <item> tag requires a 'drawable' attribute or child tag defining a drawable

I created a state-list selector file item_bg_selector.xml in the drawable folder like this : <selector xmlns:android=”http://schemas.android.com/apk/res/android”> <item android:state_selected=”true” android:drawable=”@drawable/item_background_selected” /> <item android:state_focused=”true” android:drawable=”@drawable/item_background_selected” /> <item android:state_pressed=”true” android:drawable=”@drawable/item_background_selected” /> <item android:drawable=”@android:color/transparent”/> </selector> Then i define a style element <style name=”Item”> <item name=”android:layout_width”>wrap_content</item> <item name=”android:layout_height”>wrap_content</item> <item name=”android:background”>@drawable/item_bg_selector</item> </style> Then I try to create an ImageButton like this […]

How to detect a layout resize?

Dianne Hackborn mentioned in a couple threads that you can detect when a layout as been resized, for example, when the soft keyboard opens or closes. Such a thread is this one… http://groups.google.com/group/android-developers/browse_thread/thread/d318901586313204/2b2c2c7d4bb04e1b However, I didn’t understand her answer: “By your view hierarchy being resized with all of the corresponding layout traversal and callbacks.” Does […]

Why do items disappear when I scroll the listView?

My application use a ListView which display different items in the cell. it must have photo and name, but it happens to have description and icons. The problem is: when I scroll the ListView and come back to the top, the description and icons have disappeared, there are only image and name. I have the […]

Android: trying to understand android:layout_weight

I’m trying to divide a page in three parts. I’d like to do it in percentage values, however that is not supported by Android. Instead I have to use android:layout_weight. But I have a hard time understanding it and getting it right. Especially how the actual size gets calculated. Is there a way to get […]

Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.