Is it possible to use a ViewGroup for Empty ListView?
I have a ListActivity
whose layout looks like
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="@android:id/list" android:cacheColorHint="@color/transparent" style="@style/FullWidth.NoteList" />
<LinearLayout android:id="@android:id/empty" style="@style/FillParent">
<ImageView style="@style/NoNotesImage" />
<TextView android:text="@string/no_notes" style="@style/Shadowed.NoNotesText" />
<Button android:id="@+id/note_add" android:text="@string/note_add" style="@style/Shadowed.Button.Blue"/>
</LinearLayout>
</LinearLayout>
The styles relevant here.
<?xml version="1.0" encoding="utf-8"?>
<style name="Shadowed">
<item name="android:shadowDx">1.1</item>
<item name="android:shadowDy">1.1</item>
<item name="android:shadowRadius">1.1</item>
</style>
<style name="NoNotesImage">
<item name="android:layout_width">fill_parent</item>
开发者_运维知识库 <item name="android:layout_height">wrap_content</item>
<item name="android:gravity">center</item>
<item name="android:layout_marginTop">80.5dip</item>
<item name="android:layout_marginLeft">20dip</item>
<item name="android:src">@drawable/bg_no_notes</item>
</style>
<style name="Shadowed.NoNotesText">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:gravity">center</item>
<item name="android:textSize">10sp</item>
<item name="android:textColor">@color/no_notes_text</item>
<item name="android:shadowColor">@color/no_notes_shadow</item>
</style>
<style name="FillParent">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
</style>
However, my empty list view consist only of the ImageView
listed first inside the nested LinearLayout
.
This seems like a reasonable thing to do but I don't completely understand Android's layout rules yet.
Well, I'm going to take a shot in the dark. The LinearLayout should work but I'm guessing that you're accidentally pushing Views off the screen. I bet that LinearLayout's android:orientation is accidentally being set to "horizontal" and the ImageView's layout_width is "fill_parent"; doing that will block the TextView and the Button. You probably just need to change the LinearLayout's android:orientation to "vertical" and it will work as expected.
精彩评论