Reputation: 23
I want my text view inside card view to stretch only to card view width and fit in multiline based on text length.But what happening it is changing the card view width also. Please find the below layout and try to change the text length.
<?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"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:columnCount="3"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:id="@+id/grid"
>
<FrameLayout
app:layout_columnWeight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content
"
android:id="@+id/frame1"
>
<android.support.v7.widget.CardView
android:id="@+id/card1"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="96dp"
android:layout_marginRight="3dp"
app:cardCornerRadius="4dp">
<TextView
android:id="@+id/questionText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollHorizontally="false"
android:maxLines="10"
android:text="ejweqfewdawdewasdfewefwsefwsfw"/>
<View
android:id="@+id/userResponseView"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="right|top"
android:visibility="visible"
android:background="@drawable/right"
/>
</android.support.v7.widget.CardView>
</FrameLayout>
<ImageView
android:id="@+id/image1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/line"
android:visibility="visible"/>
<FrameLayout
app:layout_columnWeight="1"
android:id="@+id/frame2"
>
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card2"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_marginLeft="3dp"
android:minHeight="96dp"
card_view:cardCornerRadius="4dp">
<TextView
android:id="@+id/questionText5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:text="answer1"/>
</android.support.v7.widget.CardView>
</FrameLayout>
<FrameLayout
app:layout_columnWeight="1"
android:id="@+id/frame3"
android:layout_marginTop="16dp"
>
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card3"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="96dp"
android:layout_marginRight="3dp"
android:layout_gravity="center"
card_view:cardCornerRadius="4dp">
<TextView
android:id="@+id/questionText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:text="question2"/>
</android.support.v7.widget.CardView>
</FrameLayout>
<ImageView
android:id="@+id/image2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/line"
android:visibility="visible"/>
<FrameLayout
app:layout_columnWeight="1"
android:id="@+id/frame4"
android:layout_marginTop="16dp"
>
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card4"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_marginLeft="3dp"
android:minHeight="96dp"
card_view:cardCornerRadius="4dp">
<TextView
android:id="@+id/questionText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:text="answer2"/>
</android.support.v7.widget.CardView>
</FrameLayout>
</android.support.v7.widget.GridLayout>
</RelativeLayout>
Upvotes: 0
Views: 1471
Reputation: 533
Make your cardview's width to android:layout_width="wrap_content"
or give it a fixed size of your preference for Eg: android:layout_width="20dp"
then textView will not expand beyond cardView's width
Upvotes: 0