Question

Just now the layout in my Listview has gotten slightly messed up: The textviews in every row are now wrapped while they should be free to fill the screen horizontally.

EDIT: updated text to more accurately describe the current situation. EDIT2: This is want the UI is supposed to look like:

The above part is what it's supposed to look like and the below part is what is currently displaying.

My ListView layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">

<TextView 
    android:id="@+id/goal_name"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:layout_alignParentLeft="true"/>

<LinearLayout
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:orientation="horizontal"
    android:layout_centerHorizontal="true">

    <TextView 
        android:id="@+id/goal_progress"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"/>

    <TextView
        android:id="@+id/seperator"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="@string/seperator"/>

    <TextView 
        android:id="@+id/goal_limit"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"/>

    <!-- 
    <ProgressBar
        android:id="@+id/progress_bar"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"/>
     -->

  </LinearLayout>

</RelativeLayout>

My main page layout:

<LinearLayout 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"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="nl.tizin.healthapp.GoalMainScreen$PlaceholderFragment">

<RelativeLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_marginBottom="5dp">

    <TextView
        android:id="@+id/name_header"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:text="@string/name_header_text"
        android:textStyle="bold"/>

    <TextView 
        android:id="@+id/day_header"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:text="@string/day_header_text"
        android:textStyle="bold"/>

</RelativeLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ListView
        android:id="@+id/list_of_goals"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">     
    </ListView>

    <TextView
        android:id="@+id/empty_goal_list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/no_goals_added"/>

</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <Button
        android:id="@+id/add_exercise_goal_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/add_exercise_goal_button_text"
        android:onClick="addExerciseGoal"/>

    <Button
        android:id="@+id/add_food_goal_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/add_food_goal_button_text"
        android:onClick="addFoodGoal"/>

</LinearLayout>

My onCreate method:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.goal_main_screen);
    mGoalList = (ListView) findViewById(R.id.list_of_goals);
    mGoalList.setEmptyView((View) findViewById(R.id.empty_goal_list));
    mGoalList.setOnItemClickListener(new OnItemClickListener(){
        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            Cursor c = (Cursor) mGoalList.getItemAtPosition(position);
            //Get ID of goal and increment day value
            checkInGoal(c.getInt(0));
            System.out.println(c.getString(1));
        }
    });
    populateList();

I'd appreciate it if someone could help as I've been staring at this for way too long.

Était-ce utile?

La solution

For starters your listview layout does not close the RelativeLayout tag.

You might want to add the attribute:

android:layout_toRightOf="@+id/goal_name"

in your LinearLayout

Might I suggest weighting your views:

add attribute:

android:layout_weight="<some percentage>"

in each child view (ie: .8)

and attribute:

android:weightSum="1"

to the parent view

EDIT

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" 
     >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" 
        android:weightSum="1"
        >

         <TextView
            android:id="@+id/goal_name_header"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:gravity="left"
            android:layout_weight=".3"
            android:text="Goal Name Header"

            />

        <TextView
            android:id="@+id/goal_progress_header"
            android:layout_width="0dp"
            android:layout_height="wrap_content" 
            android:layout_weight=".7"
            android:gravity="left"
            android:text="Progress Header"

            />

    </LinearLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" 
        android:weightSum="1"
        >

        <TextView
            android:id="@+id/goal_name"
            android:layout_width="0dp"
            android:layout_height="wrap_content" 
            android:layout_weight=".3"
            android:gravity="left"
            android:text="Goal Name "

            />

        <TextView
            android:id="@+id/goal_progress"
            android:layout_width="0dp"
            android:layout_height="wrap_content" 
            android:layout_weight=".7"
            android:gravity="left"
            android:text="Progress "

            />


    </LinearLayout>

</LinearLayout>

Autres conseils

It looks like you changed from LinearLayout to RelativeLayout. Close the RelativeLayout tag and remove the orientation attribute.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top