Dynamically expanding widgets on Android UI - android-widget

I'm trying to create a simple Android UI that consists of a EditText and Button widget. However I'm having some problems with setting the layout properties. The UI is supposed to look like this:
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒
Left is the EditText and right is the Button. The Button (ImageButton) has a widths of approximately 50x50 which I would like to be fixed. The TextBox however should span the entire free space up to the button but I am not able to get this working. I would like to have this work dynamically so I don't have to specify a different layout for different screen sizes or orientation (if this is possible at all).
This is my first Android app so I appreciate any suggestions on how to best build the UI for an application.
Thanks,
b3n

This should place the elements how you wanted.
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal">
<TextView
android:layout_weight="0.5"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="text"/>
<Button
android:id="#+id/b1"
android:text="test"
android:layout_height="50px"
android:layout_width="50px"
/>

Related

ListView and WebView Scrolling

I am developing an app which have a webview component and a list view component. I have a transparent layout on my webview to capture all the user event. I execute a javascript scroll function on the webview whenever the user is trying to scroll. Every-time the function is called, webview get scrolled and it returns a value which is used to scroll my list view. To scroll my list view I am using myListView.setSelectionFromTop(pos, y). The problem here is if I disable scrolling for the listview, the webview scrolls smoothly. But if the listview is enable, the webview doesn't scroll smoothly. My ultimate aim is to scroll listview and webView simultaneously. But it seems while scrolling listview it blocks the UI thread and hence make the scrolling of the webview slow.
Can anyone suggest me how to get this to work?
#MysticMagic Here is my xml layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:widget="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF">
<RelativeLayout
android:layout_width="40dp"
android:layout_height="match_parent"
android:layout_marginTop="26dp"
android:background="#FFFFFF"
android:gravity="center"
android:id="#+id/relLayout">
<ListView
android:id="#+id/listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:dividerHeight="1dp"
android:divider="#D3D0D9"
android:layout_centerInParent="true"
android:background="#E2E2E2"
android:cacheColorHint="#android:color/transparent"
android:footerDividersEnabled="false"
android:gravity="center"
android:layout_gravity="center"
android:listSelector="#android:color/transparent"
android:visibility="visible"
android:fillViewport="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:id="#+id/webLayout"
android:background="#FFFFFF"
android:layout_height="fill_parent"
android:layout_toRightOf="#+id/relLayout">
<WebView
android:id="#+id/webView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="none">
</WebView>
<com.example.view.CustomView
android:id="#+id/transparentView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"/>
</RelativeLayout>

text in textview seems to be in white color in real device but in emulator is OK

The properties in a vertical layout are
<LinearLayout
android:id="#+id/buscador"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:focusable="false"
android:focusableInTouchMode="false"
android:orientation="horizontal" >
<AutoCompleteTextView
android:id="#+id/autoCompleteTextView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="#string/searchcity"/>
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="#string/climaB" />
</LinearLayout>
In the Eclipse emulator for Android 3.0, the submitted text is perfectly seen but in my Android Froyo tablet it is not >:( . The app has minimun SDK = 8. Somebody had the same issue? What can be going on ? I also tried with Plain text TextView but in this case there was not problem neither of both, emulator and device. Sorry, forget to mention that the text in the textview is in color white when run the app in the Tablet, in the emulator is visible in dark color (black).
For Tablet and some android versions default Text Color is white , That is why you are getting white text color, add android:textColor attribute
check if you have dark mode on. If yes try again after disabling it.

TextView blocking ListView onItemClickListener

I have simple list view with list items defined by following layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/list_item_selector" >
<TextView
android:id="#+id/menuItemTextView"
android:clickable="false"
android:focusable="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#00000000"
android:padding="20dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/blue"
android:textIsSelectable="true" />
<ImageView
android:id="#+id/arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:paddingRight="10dp"
android:src="#drawable/arrow" />
> </RelativeLayout>
When I click TextView the listView.onItemClickListener is not called. The problem occurs on Android 4. Android 2.x is OK. Is there any trick to pass an event from TextView to its ListView without defining onClickListner on the TextView?
In your main activity just make you listview as focusable true. This worked for me. If you are using a custom list view the focus is passed to its childs and not the list so to get the focus back to listview use
listView.focusable(true);
and the other things as textview just set their focus as false.
It was the android:textIsSelectable="true" attribute. Don't follow lint hints blindly.
android:inputType="textMultiLine" can also cause this problem. If you've included that attribute in your TextView xml, try removing it.

How to change TabWidget's background color from XML in Android

I have come across this problem. I have a tab widget on top of the view, with four tabs in it. I have been asked to change the background color of the whole tab view area. Not for any tab, but the whole area of that tab view.
I also been asked for not changing any source code for some branding reason. So I could only do it through xml file. I searched around but seems all solution is by using java code. So I wonder if there is a way that I could change the widget background color (just color, not images) by using only resources files?
Here is my layout file for the tab layout:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"
>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/tabbackgroundcolor" />
<FrameLayout
android:layout_below="#android:id/tabs"
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"
/>
</RelativeLayout>
</TabHost>
You could see that I added "android:background="#color/tabbackgroundcolor"" in the TabWidget part, however it not work..
Thank you!

Can any one point me to this "Take a picture" widget in google plus android app. Want to know how to create a UI of that type

Can any one help me out how how this widget can be developed as in attached.The widget in the attached is of "Take a photo" or select photo" UI. Just want to know how can we create this UI widget. Any tutorials/and discussions/reference would help.Thank You.
Use hierarchyviewer tool from Android SDK. I tried.
You can learn that this menu is a custom baked dialog or activity, created from FrameLayout, ScrollView, LinearLayout and Buttons.
So to make one, you'll have to roll your own in similar style.
Here is how the xml would look like. You'd have to have a background for the FrameLayout and also 2 for the buttons. One with a full rectangle and the other without the top line. Then some margins/paddings tweaking and you should be fine.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" android:layout_gravity="center_vertical|center_horizontal">
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" android:background="#444" android:textColor="#fff" android:layout_marginBottom="1dp"/>
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" android:background="#444" android:textColor="#fff"/>
</LinearLayout>
</ScrollView>
</FrameLayout>
Note: this is based on Mice's answer.
I don't think its native android widget. May be you can find it on github try searching over there.
Use GreenDroid library, it has what you are looking for. It is a nice library with host of features. To test it download this sample application