Tag: layout

Android Spinner Dropdown arrow not displaying

my background for my fragment is white, and the arrow for the spinner does not display unless I click on it. This is the snippet from my Java file: spinner = (Spinner)v.findViewById(R.id.spinner); ArrayAdapter adapter = ArrayAdapter.createFromResource(getActivity(), R.array.accounts,R.layout.spinner_item); adapter.setDropDownViewResource(R.layout.spinner_dropdown_items); spinner.setAdapter(adapter); spinner.setPrompt(“Select an account”); This is my XMLfor the spinner_item <TextView xmlns:android=”http://schemas.android.com/apk/res/android” android:id=”@android:id/text1″ style=”?android:attr/spinnerItemStyle” android:singleLine=”true” android:layout_width=”match_parent” android:layout_height=”wrap_content” […]

how to specify width and height of a drawable item

Hi is there anyway of providing width and height of a drawable defined in drawable.xml in drawable folder. Example: <selector xmlns:android=”http://schemas.android.com/apk/res/android”> <item android:state_pressed=”true” android:drawable=”@drawable/button_pressed” /> <!– pressed –> <item android:state_focused=”true” android:drawable=”@drawable/button_focused” /> <!– focused –> <item android:drawable=”@drawable/button_normal” /> <!– default –> </selector> I wanted to specify width and height maybe somehow using “scale” tag inside […]

Add newlines to a text resource in Android?

I have a custom Dialog that contains only a TextView to display some text in my application. The documentation lists that only the b, i, u, tt, big, small, sup, sub, and strike tags are supported. I really need to add some newlines for readability. Do I need to change to a more complicated layout, […]

How to center a Custom View on Android?

I am trying to center the view for different resolutions using the layout, and gravity properties, but it’s not working. Is there a way to make the custom view center horizontally across different resolutions? Do I need to do something on the onMeasure method ? Here is one of the things I am trying right […]

How do I change the text style of a spinner?

I’m creating a spinner in my layout xml files and setting an string array to this spinner. If I change the textstyle of the spinner the text is not affected by the changes. I read in the googlegroups that a spinner has no text and therefore the textstyle can not be changed and I have […]

Android linear layout align center and right

This is what I have: <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout android:id=”@+id/LinearLayout01″ android:layout_width=”fill_parent” android:layout_height=”fill_parent” xmlns:android=”http://schemas.android.com/apk/res/android” android:orientation=”vertical” android:background=”#FFFFFF”> <LinearLayout android:id=”@+id/LinearLayout01″ android:layout_width=”fill_parent” android:layout_height=”wrap_content” xmlns:android=”http://schemas.android.com/apk/res/android” android:orientation=”horizontal” android:background=”#E30000″ android:layout_gravity=”center_horizontal|center_vertical” android:gravity=”center_horizontal|center_vertical”> <TextView android:id=”@+id/TextView00″ android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:textColor=”#FFFFFF” android:textSize=”20px” android:textStyle=”bold” android:text=”Something” android:gravity=”right|center_vertical” /> <LinearLayout android:id=”@+id/LinearLayout01″ android:layout_width=”fill_parent” android:layout_height=”wrap_content” xmlns:android=”http://schemas.android.com/apk/res/android” android:orientation=”horizontal” android:gravity=”right|center_vertical” android:layout_gravity=”center_vertical” android:background=”#E30000″> <Button android:id=”@+id/btnCalls” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:drawableLeft=”@drawable/icon” android:gravity=”right|center_vertical” /> </LinearLayout> </LinearLayout> </LinearLayout> And I […]

LinearLayout minHeight not working with weigth=“1”

I tried the all afternoon to get the minHeight attribute to work. What I want is the linearMe layout to: Stretch from the bottom of the screen to the bottom of the ListView when the ListView has just a few elements. I need to be able to fill the linearMe layout with a picture for […]

Android – common techniques for scaling screen layouts

I realise this topic has been covered to death, and I have read the official and unofficial developer guides on it so know the theory. But I’m still unsure which path to take to ensure my app looks good on multiple screen sizes. My app is a simple navigation style app which is designed to […]

addOnLayoutChangeListener vs addOnGlobalLayoutListener vs post(Runnable r)

PROBLEM: Suppose we have simple case: we have view and we have to show some data on this view. We use static method showData(View view) to do this. I want to know the exact moment when view layout is measured and I can access getWidth() getHeight() and be sure that this is final width and […]

Preventing shapes scaling in a LayeredList without using Bitmap

Trying to use LayerDrawable (defined in XML as layer-list) to layer several shape drawables onto one another; to be used as a background for a layout. The Android guide (for LayerList) says: All drawable items are scaled to fit the size of the containing View, by default. Thus, placing your images in a layer list […]

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