View over ListView leads to ClassCast Exception - android

I am using a Relative Layout(RL) to Hold a List View(lv) and a few bunch of other widgets like Text View(tv), Edit Text(et), then a few Buttons(btn) and finally one Progress Bar(pb).
Scenarios
1. When i add child Views to the Parent Container View viz. Relative Layout(rl), in the order: RL(Btn1->Btn2->tv1->tv2->LV->pb). Then we have no problem, i mean No Exception, No Problem.
2. But when i do the ordering change like RL(tv1->tv2->LV->Btn1->Btn2->pb). then i am getting a classcast Exception.
Note: the two buttons should be over the listview, as both of them are social website buttons, i mean Facebook and Twitter.
XML Code:
<RelativeLayout
android:id="#+id/rlfornews"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:layout_marginTop="5dip"
android:background="#drawable/newsbg"
android:orientation="vertical"
android:paddingBottom="5dip" >
<Button
android:id="#+id/btnbasetw"
android:layout_width="30dip"
android:layout_height="30dip"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginBottom="10dip"
android:layout_marginLeft="5dip"
android:layout_marginRight="10dip"
android:background="#drawable/twitter_icon"
android:visibility="gone" />
<Button
android:id="#+id/btnbasefb"
android:layout_width="30dip"
android:layout_height="30dip"
android:layout_centerVertical="true"
android:layout_marginBottom="10dip"
android:layout_toLeftOf="#id/btnbasetw"
android:background="#drawable/facebook_icon"
android:visibility="gone" />
<TextView
android:id="#+id/tvnewscon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dip"
android:background="#drawable/newstitle"
android:gravity="center_vertical"
android:paddingLeft="8dip"
android:shadowColor="#color/black"
android:shadowDy="1"
android:shadowRadius="1"
android:text="#string/news"
android:textColor="#color/white" />
<TextView
android:id="#+id/tvfornews"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/tvnewscon"
android:layout_marginTop="10dip"
android:gravity="center"
android:text="#string/no_data_found"
android:visibility="gone" />
<ListView
android:id="#+id/lvdashboardnews"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#id/tvnewscon"
android:padding="4dip"
android:visibility="visible" >
</ListView>
<ProgressBar
android:id="#+id/pbfornews"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
Note: The Progress Bar might be below, but it is just to user information, that some data is loading. and when i get that data, i am making its Visibility to VIEW.GONE state, and the List View being already there !
My question is when i follow the First Scenario, even though i have a Progress Bar from the entire time, i am not getting a Class Cast Exception. But i am getting the exception, when i change to Scenario 2. So why i am i getting it?

I am not sure about these but may be the reason is you have used the android:layout_below = "#id/textview" instead of use these android:layout_below = "#+id/textview" all UI.
If you can do these UI using the LinearLayout.

Related

how to rearrange my textview in my relativelayout?

Here's my layout screenshot:
How can I arrange all these TextView for them to have a good format (heading being Taking responsibility (means being aware)..) alignment etc.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Menu"
android:background="#android:color/holo_blue_bright"
>
<TextView
android:text="*Follow safety guide for moving around the town and between towns."
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView25"
android:gravity="left"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="51dp" />
<TextView
android:text="*Avoid crowds and do not participate actively in demonstrations even when it is related to programme work."
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView25"
android:gravity="left"
android:layout_below="#+id/textView25"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="15dp" />
<TextView
android:text="*Avoid crowds and do not participate actively in demonstrations even when it is related to programme work."
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView25"
android:gravity="left"
android:layout_marginBottom="23dp"
android:layout_above="#+id/textView25"
android:layout_toRightOf="#+id/textView25"
android:layout_toEndOf="#+id/textView25" />
<TextView
android:text="*keep this briefing pack in an accessible place, and the emergency numbers in your mobile phone memory"
android:layout_width="wrap_content"
android:gravity="bottom"
android:layout_height="wrap_content"
android:id="#+id/textView28"
android:layout_above="#+id/textView25"
android:layout_toRightOf="#+id/textView25"
android:layout_toEndOf="#+id/textView25"
android:layout_marginBottom="46dp" />
<TextView
android:gravity="center"
android:textColor="#000"
android:textSize="15dp"
android:text="Taking resposibility(means being aware)"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView22"
android:layout_marginTop="18dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:text="*Avoid moving around town by yourself and always make others aware of your location."
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:id="#+id/textView25"
android:layout_marginTop="76dp"
android:layout_below="#+id/textView22"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:text="*Share any security information that might have implications for Ballloon Ventures to the Country Manager or pc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView24"
android:gravity="left"
android:layout_below="#+id/textView26"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="30dp" />
<TextView
android:text="*If using host home accommondation,check that it is secure.if it is not,tell the Programme Coordinator"
android:layout_width="wrap_content"
android:gravity="bottom"
android:layout_height="wrap_content"
android:id="#+id/textView28"
android:layout_marginTop="14dp"
android:layout_below="#+id/textView24"
android:layout_alignRight="#+id/textView25"
android:layout_alignEnd="#+id/textView25" />
<TextView
android:text="*Report all incidents to your Programmer Cordinator."
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView26"
android:gravity="left"
android:layout_below="#+id/textView25"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="55dp" />
</RelativeLayout>
Because if I drag one TextView it affecting all other TextView.
As #GabeSechan said, you need to learn what android:layout_xxx properties in RelativeLayout means.
When you moving a View in RelativeLayout via Layout Editor, you need to consider some of the following properties in your layout:
android:layout_above="#+id/textView25"
android:layout_below="#+id/textView24"
android:layout_toRightOf="#+id/textView25"
android:layout_toEndOf="#+id/textView25"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_above="#+id/textView25" means that you want the View above textView25 view.
android:layout_below="#+id/textView24" means that you want the View below textView25 View.
The following properties means that you want the view to the right side of TextView25 View:
android:layout_toRightOf="#+id/textView25"
android:layout_toEndOf="#+id/textView25"
The following properties means that you want the view to align with the left side of the parent layout:
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
If you want to edit views position in a RelativeLayout, please don't depends with drag and drop via Layout Editor. You better do it manually except you want to have a headache later. Use Layout Editor to view the design result.
Design with a paper or imagination first, then code it after that.
Try to learn it from:
Relative Layout
Constructing View Layouts
The best practice for doing that would be to open a splitview between your code and design views and then editing the code to place the text in the correct location, using attributes such as padding, margin, aligning, below, above, etc. refer to this guide for positioning stuff in relative layout and combine it with other formatting attributes such as margin and padding.

I'm completely stumped as to which Android Adapter to inherit/use

I have a data-structure which is of type:
ArrayList<ArrayList<String>>;
...It contains a set of elements of a news feed; each element is itself a list of fields and each field is a tuple(key:value) where both key&value are of type String.
NOTE: the reason fields are stored in ArrayList is I don't always know how many the feed-parser will spurt out.
The view:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:id="#+id/news"
android:text="#string/news_and_events"
android:layout_row="6"
android:layout_column="4"
android:layout_columnSpan="3"
android:layout_rowSpan="3"
android:width="180dp"
android:height="245dp"
android:layout_marginBottom="10dp">
<!--FEED-->
<ListView
android:id="#android:id/list"
android:layout_height="match_parent"
android:layout_width="match_parent"
/>
</RelativeLayout>
The row-template I want to use is:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<ImageView
android:id="#+id/picture"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_marginRight="6dip"
android:contentDescription=""
/>
<!--STARTING WITH title-->
<TextView
android:id="#+id/title"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_toRightOf="#id/picture"
android:ellipsize="marquee"
android:singleLine="true"
android:text=""
android:textSize="20sp"
/>
<TextView
android:id="#+id/body"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" />
</RelativeLayout>
As you can see there are 3-fields: title, body, image (a news feed).
So I'm completely stumped as to what type of adapter I should use.
All the ones' I've looked at don't seem to match what I want to do; specifically because of the data-structure I'm using.
Perhaps I should use a cursor adapter?
If so, how would I map this into a Relational-database?!
I think you should try using a BaseAdapter, it's the most flexible adapter Android has(I think)...
By doing so, you can implement a custom Adapter, which goes thru the ArrayList(using 2 cycles for extracting) and then parsing it to the visual components you specified.
Since it's constructor receives the context, the view and the data, you'll have the ImageView and so, there.

ImageView dissapearing after setting an ID

I'm programatically adding views into my layout inside a for loop.
The xml file of the layout I'm adding is like this one:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout_consulta_item_list"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/imageView_consulta_action"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/LinearLayout_dados_consulta"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/LinearLayout_dados_consulta"
android:layout_centerHorizontal="true"
android:layout_centerInParent="false"
android:adjustViewBounds="true"
android:maxWidth="70dp"
android:padding="10dp"
android:scaleType="centerInside"
android:src="#drawable/estrela_off" />
<LinearLayout
android:id="#+id/LinearLayout_dados_consulta"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:layout_toLeftOf="#+id/imageView_consulta_action"
android:background="#660000"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="#string/origem"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#ffaaaa"
android:textSize="10sp" />
<TextView
android:id="#+id/textView_origem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="YYY"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#eeeeee" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:text="#string/data_ida"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#ffaaaa"
android:textSize="10sp" />
<TextView
android:id="#+id/textView_data_ida"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2014-05-05"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#eeeeee"
android:textSize="15sp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
In my main_activity, I call the constructor:
for (int i=0;i<resultList.length-1;i++){
RelativeLayout viewToLoad = (RelativeLayout)LayoutInflater.from(this).inflate(R.layout.consulta_item, null);
ll.addView(viewToLoad);
ImageView ImgConsulta_action = (ImageView)findViewById(R.id.imageView_consulta_action);
LinearLayout dados_consulta = (LinearLayout)findViewById(R.id.LinearLayout_dados_consulta);
dados_consulta.setOnLongClickListener(...);
ImgConsulta_action.setOnLongClickListener(...);
Well, I keep setting SetText for all the views in the layout and so on.
But, in order to make the setOnClickListener to work for each view, I must set a id to the views inside the for loop:
dados_consulta.setId(4000+i);
ImgConsulta_action.setId(5000+i); //(*lastline)
The weird thing is happening is that:
If I comment this last line, the layout is inserted correctly with the imageview showing a star as it is suposed to do and the listener at "dados_consulta" works fine.
But if I remove the comment at this last line, the star dissapear from the screen.
Can anybody help me to understand what is going on?
I had an layout params referenced to the ID of the layout elements at the original view.
Since I have to change the ID dynamically while I'm adding this layout several times into my activity, I also need to reset the layoutparams to the new Ids.
So, I added this lines:
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)ImgConsulta_action.getLayoutParams();
params.addRule(RelativeLayout.ALIGN_TOP, dados_consulta.getId());
params.addRule(RelativeLayout.ALIGN_BOTTOM, dados_consulta.getId());
ImgConsulta_action.setLayoutParams(params);
RelativeLayout.LayoutParams paramsDadosConsulta = (RelativeLayout.LayoutParams)dados_consulta.getLayoutParams();
paramsDadosConsulta.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
paramsDadosConsulta.addRule(RelativeLayout.LEFT_OF, ImgConsulta_action.getId());
dados_consulta.setLayoutParams(paramsDadosConsulta);
Now it's working perfectly.
Notice that the problem is not about the layout disappearing it was about a layout get in front of the other one. (making this other one invisible)

Android RelativeLayout Design issues

I designed one layout which have total 4 RelativeLayout one is outer cover and 3 are child of it. When I put White color in the outer layout than no spaces are left but when I put 9patch image as drawable image than little default padding/margin are left. Is there any properly which solve the padding/margin issue? I have tried margin negative but it will hide bit layout I think it is not proper solution, here is my layout
when I put white color as background than my layout look like
Here is the following code of my layout
<RelativeLayout
android:id="#+id/DetailSection1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/HeaderLayout"
android:layout_toLeftOf="#+id/DetailSection2"
>
<TextView
android:id="#+id/lblRestaurantName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/DetailSection1"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:textColor="#color/heding_font"
android:textSize="#dimen/headingFont"
android:text="Restaurant Name" />
<ImageView
android:id="#+id/imgpin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/lblRestaurantName"
android:layout_margin="5dp"
android:src="#drawable/pin" />
<TextView
android:id="#+id/lblAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/lblRestaurantName"
android:layout_marginTop="5dp"
android:layout_toRightOf="#+id/imgpin"
android:text="Address"
android:textColor="#color/restaurant_list_font"
android:textSize="#dimen/lableNormalFont"
/>
<ImageView
android:id="#+id/imgphone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/lblAddress"
android:layout_margin="5dp"
android:src="#drawable/phn" />
<TextView
android:id="#+id/lblMobile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/lblAddress"
android:layout_marginTop="5dp"
android:layout_toRightOf="#+id/imgphone"
android:text="Mobile"
android:textColor="#color/restaurant_list_font"
android:textSize="#dimen/lableNormalFont"
/>
<ImageView
android:id="#+id/imgstar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/lblMobile"
android:layout_margin="5dp"
android:src="#drawable/star" />
<TextView
android:id="#+id/lblStar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/lblMobile"
android:layout_marginTop="5dp"
android:layout_toRightOf="#+id/imgstar"
android:text="Star"
android:textColor="#color/restaurant_list_font"
android:textSize="#dimen/lableNormalFont"
/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/DetailSection2"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignBottom="#+id/DetailSection1"
android:layout_toLeftOf="#+id/DetailSection3"
android:layout_toRightOf="#+id/lblStar" >
<ImageView
android:id="#+id/imgmore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:src="#drawable/read_more" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/DetailSection3"
android:layout_width="95dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/HeaderLayout"
android:layout_gravity="center"
android:layout_centerInParent="true"
android:background="#drawable/photo_cover" >
<ImageView
android:id="#+id/imgRestaurant"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/lblMobile"
android:layout_margin="5dp"
android:src="#drawable/rihanna" />
</RelativeLayout>
</RelativeLayout>
From the 9-patch drawable image you posted:
The bottom line which indicates the horizontal data population on the view wasn't drawn from the starting point of left.
I am not sure about it. And I know I wasn't clear in explaining the above line.
Just check this:
Consider the below 9-patch is used as a background for a TextView. If you put some text in it, it will start from the area where the bottom line is drawn. Which mean it will start from the left and go all the way to right.
If you use the following 9-patch as a background and try the same thing which you did above. Will result in Text not written from the left. It leaves a bit padding.
That is the reason why you get such result. Of course I am 100% sure about it.
So, just to find out if this works. Try changing the bottom line to fill complete image.
I think you better apply the background color for which layout you want exactly.And one more keep the code so that we can understand easily what is your issue.

How to design Twitter interface Layout in Android

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

Categories

Resources