I am trying to modify the design of Spinner widget. I can change the background, but I can't find a way to change the arrow icon on the right side. Is there a way to do it?
Thanks!
The whole thing is a single 9 patch png image. I've modified the entire look of spinners before by replacing the images. See this page: http://androiddrawableexplorer.appspot.com/
Specifically look at btn_dropdown_normal.9, btn_dropdown_pressed.9, btn_dropdown_selected.9 and btn_dropdown_disabled.9
You just need to provide your own versions of those images.
Also, you can place your "spinner bar" layout in a FrameLayout, together with the real spinner but set to invisible:
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="32dip"
>
<Spinner
android:id="#+id/theSpinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="invisible"
/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="32dip"
android:background="#drawable/my_background"
android:padding="6dip"
android:clickable="true"
android:onClick="spinnerBarReplacementClicked"
>
<ImageView
android:id="#+id/replacementSelectImg"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="#drawable/my_drawable"
/>
<TextView
android:id="#+id/replacementSelectText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="4dip"
android:layout_toLeftOf="#id/replacementSelectImg"
android:textColor="#000000"
android:textSize="14sp"
android:ellipsize="marquee"
android:singleLine="true"
/>
</RelativeLayout>
</FrameLayout>
and pass the clicks from your layout to the real spinner
private Spinner mSpinner;
mSpinner = (Spinner) findViewById(R.id.theSpinner);
public void spinnerBarReplacementClicked(View pV){
mSpinner.performClick();
}
Related
I want to make one application which contains multiple choice question. Each question has three option. I want to show that option with one background image. And also want to change the color of that image randomly for each question. How can i do that?
It is possible to create list view by putting differnt background image for each row?
Result.xml
<LinearLayout
android:id="#+id/linearlayoutans"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="30dp"
android:layout_toLeftOf="#+id/chrono"
android:orientation="horizontal" >
<TextView
android:id="#+id/txt_ans_true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/ic_launcher"
android:gravity="center"
android:textColor="#000000" />
<TextView
android:id="#+id/txt_ans_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/ic_launcher"
android:gravity="center"
android:textColor="#000000" />
<TextView
android:id="#+id/txt_ans_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/ic_launcher"
android:gravity="center"
android:textColor="#000000" />
</LinearLayout>
It is possible to create list view by putting differnt background
image for each row?
Yes. Take a look at articles on the internet that back a listview with a custom adapter and a custom view. This is done from the getView() method and there is no shortage of examples / tutorials out there.
I'm trying to set my TextView to the left of an ImageButton, but I can't seems to find this option.
I was expecting to use something like android:layout_alignLeft, but this option is missing.
I've tried to google the issue, but couldn't find any relative results.
Without it my TextView overlaps the ImageButton and I want to avoid it.
UPDATE
The full xml code is too complex, but here is the important part of it:
<FrameLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:background="#color/white"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_toLeftOf="#+id/frameLayoutBalanceClosed">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/button_edit_nickname"
android:id="#+id/card_closed_control_editNickname" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/card_closed_description_nickname"
android:layout_margin="8dp" android:layout_gravity="left"/>
</FrameLayout>
I think what you need is a RelativeLayout. You can specify your TextView to the left of your ImageView with it's specifications. Your code would look something like this:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/imagebutton1" />
<ImageButton
android:id="#+id/imagebutton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
The reason FrameLayout isn't working is because it's purpose is to overlay items on top of each other, which wouldn't work at all!
If that isn't what you're looking for, you could also use a TableLayout in which items are arranged in columns.
In my android app i want to design a layout exactly like twitter layout with a Image and Text View.
See the following screenshot
Please help me with this. How can i design this layout ?
Update:
Forget about background images and top bar. I am requiring 6 images and textviews. In the below image twobirds with Tweets(167), Lists, Mentions, Retweets etc.,
What you want is fairly simple, tho I am sure there are more fancy way's of doing this then i'm
about to show you.
For my application I used 4 ImageButtons, but the principle is the same for 4 or 6 buttons.
This is my XML layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="#+id/actionbar_layout"
android:layout_width="fill_parent"
android:layout_height="45dip"
android:background="#drawable/actionbar_background"
android:gravity="center_vertical">
<TextView
android:id="#+id/tekst"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="App name"
android:textColor="#FFFFFF"
android:textSize="18dp"
android:layout_marginLeft="5dp"
android:textStyle="bold"/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/button_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_below="#id/actionbar_layout">
<ImageButton
android:id="#+id/button_schedule"
android:src="#drawable/schedule_icon"
android:scaleType="fitCenter"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="40dp"
android:background="#FFFFFF"
/>
<TextView
android:id="#+id/text_schedule"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:text="Rooster"
android:textSize="20dp"
android:layout_below="#id/button_schedule"
android:gravity="center"
/>
<ImageButton
android:id="#+id/button_locations"
android:src="#drawable/locations_icon"
android:scaleType="fitCenter"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="50dp"
android:background="#FFFFFF"
android:layout_below="#id/text_schedule"
/>
<TextView
android:id="#+id/text_locations"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:text="Links"
android:textSize="20dp"
android:layout_below="#id/button_locations"
android:gravity="center"
/>
<ImageButton
android:id="#+id/button_rss"
android:src="#drawable/rss_icon"
android:scaleType="fitCenter"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="40dp"
android:background="#FFFFFF"
android:layout_toRightOf="#id/button_schedule"
android:layout_alignParentRight="true"
/>
<TextView
android:id="#+id/text_rss"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:text="RSS"
android:textSize="20dp"
android:layout_toRightOf="#id/text_schedule"
android:layout_below="#id/button_rss"
android:layout_alignParentRight="true"
android:gravity="center"
/>
<ImageButton
android:id="#+id/button_settings"
android:src="#drawable/settings_icon"
android:scaleType="fitCenter"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="50dp"
android:background="#FFFFFF"
android:layout_toRightOf="#id/text_locations"
android:layout_below="#id/text_schedule"
android:layout_alignParentRight="true"
/>
<TextView
android:id="#+id/text_settings"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:text="Instellingen"
android:textSize="20dp"
android:layout_toRightOf="#id/text_locations"
android:layout_below="#id/button_settings"
android:layout_alignParentRight="true"
android:gravity="center"
/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/twitter_layout"
android:layout_width="wrap_content"
android:layout_height="150dp"
android:layout_alignParentBottom="true"
android:layout_below="#id/button_layout">
<Gallery android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/gallery"
android:layout_gravity="bottom"
android:layout_alignParentBottom="true">
</Gallery>
</RelativeLayout>
I pasted the whole file, so you can see how I implemented my actionbar.
But what you need is the second RelativeLayout tag.
You align your buttons/textviews by using "android:layout_toRightOf" and "android:layout_below" attributes.
Your first button is simple, the second one (the one to its right) you align with "android:layout_toRightOf="#id/first_button"
A third button (below the first button) can be aligned using "android:layout_below="#id/first_button"
The same goes for textviews, just use layout_toRightOf and layout_below to align them. The attributes only apply to the RelativeLayout.
Hope this will help you out a bit.
What you want to do is called a Dashboard pattern.
You can find implementation of ActionBar and Dashboard patterns in sources of the Google IO app. ActionBar in the file actionbar.xml (and HomeActivity.java, ActivityHelper.java), Dashboard in the file fragment_dashboard.xml (and DashBoard.java).
im sure , it's can be created like this :
image and textView mustBe on layout - so :
//start "a" code
LinearLayout oneObject ;
oneObject= new LinearLayout(this);
//need set to vertical mode
oneObject.setOrientation(LinearLayout.VERTICAL);
//it's our one object . image+text
next : TextView text = new TextView(this);
text.setText("tweets"); // or get from array
///image it's can be what you want - button, layout, textView(-____-)
// just need set on background new image . iget button - for normal clicking ;//
ImageButton image = new ImageButton(this);
image.setImageResource(r.drawable.blabla)
oneObject.addView(image);
oneObject.addView(text);
//also u need create 2 columns and add to this columns our object
//for size of oneObject - use LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(curWidth/2,curHeight/6); curWidth and curHeight - its my resolution of screen.
//end "a" code
for creating 6 objects u must rung it in cycle :
all code = "a"; so
for(int i = 0;i<6;i++)
{
a/// where a all our code
}
Hope it's help you.. also i can put more code where need some fixings
I want to make a listview with semi-transparent cells (some sort of blue with 25% opacity).
The listview is created correctly but, when i perform an scroll motion(I press and drag down or up) the list seems to activate some sort of selection mechanism witch applies a black and opaque background to the list.
Any Idea how I can get rid of this?
Below is the code and the two screens:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" android:background="#drawable/background">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:background="#drawable/my_health_title">
</ImageView>
<ListView android:id="#+id/health" android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ListView>
<TextView android:id="#+id/health_title" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textColor="#46727c"
android:textSize="14sp" android:textStyle="bold"
android:layout_marginTop="20dp" android:layout_marginLeft="30px"
android:text="Blood presure Profile">
</TextView>
<LinearLayout android:id="#+id/health_gauge"
android:layout_width="250dp" android:layout_height="35dp"
android:layout_centerVertical="true" android:layout_marginLeft="20dp">
</LinearLayout>
<TextView android:id="#+id/health_description"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textColor="#46727c" android:textSize="12sp" android:textStyle="normal"
android:layout_marginTop="150px" android:layout_marginLeft="30px"
android:text="Looks Goood">
</TextView>
<ImageView android:id="#+id/health_details"
android:background="#drawable/home_arrow_icon_margin"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentRight="true" android:layout_centerVertical="true">
</ImageView>
normal list
selected efect
I was having a nightmare with a similar problem. But I was adding the ListView dynamically, and
android:cacheColorHint="#00000000"
didn't work in this case. The solution:
Don't add ListView dynamically, cacheColorHint will not work
Hope this helps someone!
Just set the android:cacheColorHint to #00000000 on your ListView.
Notice that the color code is an 8 digit code (#AARRGGBB), which means that the first two digits represents the alpha of the color. (If you set it to a 6 digit, #000000 it won't help, because it will be still opaque. For more info on color codes click here).
Your list view should look like this:
<ListView android:id="#+id/health" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000">
</ListView>
More details and explanation can be found here.
i am doing an xml layout file, and i want to have my spinner in the right of a textview, but i am having problems... when i test the layout, my spinner is not in the correct possition, it's a little more down and it haves very small lenght, is not 180px as i said in the layout.
there is the xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/PermissionLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/perlabel"
android:layout_marginLeft="15dip"
android:layout_below="#id/salto3"/>
<Spinner
android:id="#+id/Permission"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:prompt="#string/perlabel"
android:layout_alignBaseline="#id/PermissionLabel"
android:layout_alignParentRight="true"
android:width="180px"
android:layout_marginRight="20dip"/>
<TextView
android:id="#+id/salto4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/saltodelinea2"
android:layout_below="#id/PermissionLabel"/>
<TextView
android:id="#+id/HoursRangeLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hoursrangelabel"
android:layout_below="#id/salto4"
android:layout_marginLeft="15dip"/>
<EditText
android:id="#+id/From"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:layout_alignBaseline="#id/HoursRangeLabel"
android:width="70px"
android:layout_alignLeft="#id/Email"
android:layout_marginRight="20dip"/>
<TextView
android:id="#+id/ToLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/tolabel"
android:layout_alignBaseline="#id/From"
android:layout_toRightOf="#id/From"
android:layout_marginLeft="-10px"/>
<EditText
android:id="#+id/To"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:layout_alignBaseline="#id/From"
android:width="70px"
android:layout_marginRight="20dip"
android:layout_alignParentRight="true"/>
Is it really necessary that all items in your layout are "Relative" to each other? It sure doesn't appear that way from the properties you set on each item.
I would recommend trying something like a LinearLayout, and then if it is critical a certain item is Relative to another item, use a RelativeLayout inside the LinearLayout for those particular items.