Mike
Mike

Reputation: 6839

Weight for Android textViews

I am trying to have one text view that is 3/4 of the page and 1/4 of the page with a rating bar.

Unfortunately when a long item is placed into my textview it pushses the rating bar below:

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

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

    android:id="@+id/switchOut">




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

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="6dp"
                android:layout_marginRight="6dp"
                android:layout_marginTop="4dp"
                android:layout_marginBottom="4dp"
                android:orientation="vertical"
                android:background="@drawable/bg_card">

                <!-- Card Contents go here -->

                <ScrollView
                    android:id="@+id/SCROLLER_ID"
                    android:layout_width="fill_parent"
                    android:layout_height="0dp"
                    android:layout_weight="3"
                    android:scrollbars="vertical"
                    android:fillViewport="true">



                <TextView
                    android:id="@+id/reviewToRate"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:ems="10"
                    android:textSize="15sp"
                    android:padding="5dip"

                    ></TextView>

                </ScrollView>


            </LinearLayout >

        </FrameLayout>


    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="6dp"
            android:layout_marginRight="6dp"
            android:layout_marginTop="4dp"
            android:layout_marginBottom="4dp"
            android:orientation="vertical"
            android:background="@drawable/bg_card">

            <!-- Card Contents go here -->


            <RatingBar
                android:id="@+id/reviewRatingBar"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:numStars="5"
                android:stepSize="1.0"
                android:rating="0"


                />



        </LinearLayout >

    </FrameLayout>


</LinearLayout>

Upvotes: 0

Views: 297

Answers (2)

hungryghost
hungryghost

Reputation: 9673

Your layout weights need to be at the same hierarchical level in your layout. Basically, set layout_weight="3" on your first FrameLayout (to offset the second FrameLayout with weight=1), and remove the weight from the ScrollView. It should look like this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#e5e5e5"
    android:orientation="vertical"
    android:id="@+id/switchOut">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="3">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="6dp"
            android:layout_marginRight="6dp"
            android:layout_marginTop="4dp"
            android:layout_marginBottom="4dp"
            android:orientation="vertical"
            android:background="@drawable/bg_card">

            <!-- Card Contents go here -->

            <ScrollView
                android:id="@+id/SCROLLER_ID"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:scrollbars="vertical"
                android:fillViewport="true">

                <TextView
                    android:id="@+id/reviewToRate"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:ems="10"
                    android:textSize="15sp"
                    android:padding="5dip" />

            </ScrollView>

        </LinearLayout >

    </FrameLayout>

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="6dp"
            android:layout_marginRight="6dp"
            android:layout_marginTop="4dp"
            android:layout_marginBottom="4dp"
            android:orientation="vertical"
            android:background="@drawable/bg_card">

            <!-- Card Contents go here -->

            <RatingBar
                android:id="@+id/reviewRatingBar"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:numStars="5"
                android:stepSize="1.0"
                android:rating="0" />

        </LinearLayout >

    </FrameLayout>

</LinearLayout>

Upvotes: 1

ajacian81
ajacian81

Reputation: 7579

Set a max_width value for that TextView to cut off long text if that's the behaviour you desire. Otherwise, what is the desired behaviour?

Upvotes: 0

Related Questions