0

Firstly, I am new to android so if I have missed something basic I apologise.

I have a page which has two ListViews side by side, both with varying amounts of content. I also have a TextView above the ListViews and another TextView below the listviews. These text view boxes change based on items selected in either of the two ListViews.

These two ListViews sit side by side, taking up half of the screen each, while a Textview sits directly above and directly below, both centred to the page. An image is shown below.

This is the page looking normal on load.

The problem is when I select an item from either list. I have a feeling I am missing some XML properties, but I am not sure which properties or if this is even the case. When an item is selected, let's say from the ListView on the right, the TextView at the bottom is updated with text taken from an array. The ListView also decides to change the width and I am not sure why this is.... I don't want the ListView to change width. I want it to remain taking up half of the page and half of the page only.

This is the page after an item from the right ListView has been selected.

I would also like to keep things in RelativeLayout. I also believe it is only an XML issue and not to do with the adapter or any other code so I will not include that for now. I can include it if required.

Any help would be great. Thanks in advance.

content_titles.xml my activity xml file

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".TitlesActivity">

<ListView
    android:id="@+id/unlocked_titles_list"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:longClickable="true"
    android:layout_below="@+id/current_title"
    android:layout_alignEnd="@+id/requirements"
    android:layout_marginEnd="26dp"
    android:layout_above="@+id/requirements">
</ListView>

<TextView
    android:id="@+id/current_title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="65dp"
    android:text="Current Title: Novice"
    android:textSize="24sp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"/>

<ListView
    android:id="@+id/locked_titles_list"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_alignStart="@+id/requirements"
    android:layout_marginStart="28dp"
    android:layout_above="@+id/requirements"
    android:layout_below="@+id/current_title"/>

<TextView
    android:id="@+id/requirements"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="34dp"
    android:text="temp"
    android:textAlignment="center"
    android:textSize="24sp"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"/>

</RelativeLayout>

activity_listview.xml used as the individual rows of the ListViews

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/label"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:padding="10dip"
      android:textSize="16dip"
      android:textStyle="bold" >
</TextView>

2 Answers2

4

The problems with layout could be caused by ScrollView to be the wrapper

I stumbled upon some note in http://developer.android.com/reference/android/widget/ExpandableListView.html

"...Note: You cannot use the value wrap_content for the android:layout_height attribute of a ExpandableListView in XML if the parent's size is also not strictly specified (for example, if the parent were ScrollView you could not specify wrap_content since it also can be any length. However, you can use wrap_content if the ExpandableListView parent has a specific size, such as 100 pixels."

I removed wrapping ScrollView and linear layout started working properly. Now its only to understand how to wrap the stuff to ScrollView. God help me

But anyway this is really weird behavior. I think that fill_parent is not really correct wording. When using heirarchyviewer tool I always see WRAP_CONTENT and MATCH_PARENT values for layout_width and leayout_height. So probably fill_parent is actually means match_parent which puts me in cognitive dissonance.

0

You have your layout_width properties set to wrap_content. This means that they could change as the data changes. I would recommend putting your ListViews in a LinearLayout with orientation:horizontal and set the amount of space that each element takes up with layout_weight. Here is a relevant SO question What does android:layout_weight mean?

MacLean Sochor
  • 435
  • 5
  • 14