Layout problem with ListView

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Layout problem with ListView

Postby boxy » Fri Aug 14, 2009 2:46 am

Hey All,

I'm having problems with the layout for my listview. Any info you can provide would be greatly appreciated.

Here's the background info for what I am trying to do. I have a
ListView that displays text input from the user (similar to the
Android notepad example). I want to center the text inside a
background image, a text bubble. I want the text bubble to be centered
in the view.

-------------------------------------------------------------------------

-----------------------
| |
| Hi, I'm Boxy |
| |
-----------------------

-------------------------------------------------------------------------

This is what an ideal entry should look like.

Here is the code I'm using.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip"
android:gravity="center" >

<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="fill_parent"
android:gravity="center"
android:background="@drawable/textbub" >

<TextView
android:id="@+id/txtMessage"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:paddingLeft="40dip"
android:paddingRight="20dip"
android:gravity="center" />

</LinearLayout>

</LinearLayout>

Here is what is actually displayed by my program.

-------------------------------------------------------------------------

--------------- -----------------------------------------------
| |
| Hi, I'm Boxy |
| |
--------------------------------------------------------------

-------------------------------------------------------------------------

Above is what the first entry looks like. Not what I want.
Below is what the rest of the entries look like after the first.
Definitely not what I want.

-------------------------------------------------------------------------

----------------------------
| |
| What happened? |
| |
----------------------------

-------------------------------------------------------------------------

------------------------------------
| |
| Why isn't this working? |
| |
-------------------------------------

-------------------------------------------------------------------------

-------------------
| |
| This sux! |
| |
------------------

-------------------------------------------------------------------------

So what am I doing wrong?

Bonus Question:

A RelativeLayout is supposed to be more efficient than a LinearLayout.
Can I use a RelativeLayout for what I'm trying to do instead of a
LinearLayout?
If so, how?

Thanks
boxy
Freshman
Freshman
 
Posts: 5
Joined: Fri Aug 14, 2009 2:30 am

Top

Darn it

Postby boxy » Fri Aug 14, 2009 2:49 am

The white space got removed from my diagrams.

I originally posted this question in the Android Google group and got no replies.
I'll just post a link to that.

http://groups.google.com/group/android- ... 51bc?hl=en
boxy
Freshman
Freshman
 
Posts: 5
Joined: Fri Aug 14, 2009 2:30 am

hmm

Postby boxy » Fri Aug 14, 2009 10:57 pm

Given the lack of replies on this topic, I might have underestimated the difficulty of this problem.

I posted a simpler version of this problem in this thread.

http://www.anddev.org/how_do_you_center ... t7553.html
boxy
Freshman
Freshman
 
Posts: 5
Joined: Fri Aug 14, 2009 2:30 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 7 guests