Ниже приведен код для ListView с нижним колонтитулом, проблема, с которой я сталкиваюсь, заключается в том, что нижние элементы в ListView перекрываются нижним колонтитулом. Поэтому не могли бы вы предложить какое-либо решение (потому что я много пробовал, и в каждой ситуации я получаю тот же дублирующий результат) или каким-то другим способом сделать это. Заранее спасибо. На всякий случай я также разместил код нижнего колонтитула.
<LinearLayout android:id="@+id/homeParentLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:layout_height="wrap_content"
android:layout_width="fill_parent" android:id="@+id/listV_main"
android:listSelector="@android:color/transparent"/>
<include android:id="@+id/footer" android:layout_height="wrap_content"
layout="@layout/mymenu" android:layout_width="fill_parent"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true">
</include>
</RelativeLayout>
</LinearLayout>
Код для mymenu.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:layout_gravity="bottom">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:orientation="vertical">
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text=" "
android:gravity="center"/>
<ImageView
android:id="@+id/imgSetting"
android:src="@drawable/settings_gear_icon_256"
android:layout_width="60dip"
android:layout_height="60dip"
android:layout_marginLeft="10sp"
android:clickable="true"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text=" "
android:gravity="center"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text=" "
android:gravity="center"/>
<ImageView
android:id="@+id/imgLogin"
android:layout_width="60dip"
android:src="@drawable/login_lock_256"
android:clickable="true"
android:layout_height="60dip" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text=" "
android:gravity="center"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text=" "
android:gravity="center"/>
</TableRow>
</TableLayout>
</LinearLayout>
Используйте относительный формат следующим образом: Объявите относительный макет, а затем объявите нижний колонтитул как первый элемент. Эти свойства являются важными для нижнего колонтитула:
android:layout_alignParentBottom="true"
android:id="@+id/footer_id"
Затем объявите свой listView следующим свойством:
android:layout_above="@id/footer_id"
И это должно сделать это.
Хотя RelativeLayout
обычно дает вам больше гибкости при разработке макета, в случае довольно простой компоновки вы можете использовать весы для распределения LinearLayout
экрана аналогичным образом с помощью LinearLayout
.
Обратите внимание, что наиболее заметные изменения ниже приведены в объявлении ListView
. Высота "0dp" и вес "1" заставят ListView
занимать как можно больше места (по вертикали), не выталкивая нижний колонтитул снизу. Эффективно это приведет к выравниванию нижнего колонтитула.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/homeParentLayout"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:layout_height="0dp" android:layout_weight="1"
android:layout_width="fill_parent" android:id="@+id/listV_main"
android:listSelector="@android:color/transparent" />
<include android:id="@+id/footer" android:layout_height="wrap_content"
layout="@layout/mymenu" android:layout_width="fill_parent"
android:layout_gravity="center_horizontal" />
</LinearLayout>
Я также взял на себя смелость удалить то, что, казалось, было каким-то перегруженным тегом/атрибутами от игры с RelativeLayout
.