I have a LinearLayout
which contains a single TextView
:
<LinearLayout
android:id="@+id/addTaskDescriptionLLId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp">
<TextView
android:id="@+id/descriptionTextViewId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxHeight="150dp"
android:hint="@string/abcd"
android:textColor="#A2A2A2"
android:ellipsize="end"
android:layout_margin="10dp"/>
</LinearLayout>
I've also added a condition in java file and the condition is if the TextView
has some text during opening the activity then it will be visible otherwise I used descriptionTextView.setVisibility(View.GONE);
Then I put some text in this textView
by opening a dialog and onConfirm
(clicking positive button of dialog) I did the following:
@Override
public void onConfirm(String description) {
this.description = description; //the string that I write in dialog
descriptionLL.removeAllViews(); //parent LineanLayout of TextView
descriptionLL.addView(descriptionTextView);
descriptionTextView.setText(description);
descriptionTextView.setVisibility(View.VISIBLE);
}
But the TextView height doesn't remain wrap_content as I mentioned in xml file. I've also tried:
descriptionTextView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
that also no working..Any solution?
I think the hint that you've specified in xml
is causing the problem. Remove it, it might solve.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.