我将 LinearLayout 设置为 100dp 的静态高度。然后我在其中有一个 textView,我将其高度设置为 WRAP_CONTENT。问题是,当 textView 的高度大于 100dp 时,textView 会导致 LinearLayout 完全展开以容纳 textView
我这样设置是因为我希望能够在用户单击按钮时显示和隐藏全文。我认为将线性布局的高度设置为最小值,然后在单击时将其更新为 WRAP_CONTENT 会起作用,但是当我尝试限制高度时,LinearLayout 会忽略它。我尝试将 ClipChildren 设置为 true 但这没有帮助。代码如下。我正在使用 Android Annotations,但我认为这与问题无关。
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="30dp"
android:fitsSystemWindows="true"
android:background="@color/light_grey">
<LinearLayout
android:orientation="vertical"
android:clipChildren="true"
android:background="@color/white"
android:layout_width="match_parent"
android:layout_height="100dp">
<TextView
android:id="@+id/text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
以及 Java 代码:
@EActivity(R.layout.activity_test)
public class TestActivity extends AppCompatActivity {
@ViewById(R.id.text_view)
TextView textView;
String input;
public static final String INPUT_STRING_KEY = "inputStringKeyForParser";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.input = this.getIntent().getExtras().getString(INPUT_STRING_KEY);
}
@AfterViews
public void showText() {
textView.setText(input);
}
}
有谁知道如何让 TextView 停止导致线性布局展开?谢谢!
最佳答案
尝试
<TextView
android:id="@+id/text_view"
android:layout_width="match_parent"
android:layout_height="100dp" />
关于java - 父 LinearLayout 不限制内部 TextView 的大小设置为 WRAP_CONTENT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35490424/