如何设置ViewGroup的最大宽度?我正在使用一个Theme.Dialog活动,然而,当调整大屏幕时,这看起来不那么好,它也有点轻量级,我不希望它占用整个屏幕.
我试过这个建议无济于事.此外,没有android:maxWidth像一些观点的属性.
有没有办法限制根LinearLayout,以便它只(例如)640 dip?我愿意为此换到另一个ViewGroup.
有什么建议?
我有一个TextView和一个正方形ImageView,我想以水平线性布局显示.每个应该占父视图宽度的一半,高度应该适合内容(即图像).文本应垂直居中.
附加约束是图像不应超过给定maxWidth(= maxHeight),并且应该使超出的宽度可用TextView.显然,这与上面的50/50规则相冲突.有没有办法优先考虑约束,即允许图像占用一半的空间,除非它超过给定的大小?
这些是我尝试过的布局:
第一个很好地将左侧拉伸到可用空间.但是图像占用宽度的一半以上,因为layout_weight未指定(如下图所示).
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Some text."/>
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="200dp"
android:adjustViewBounds="true"
android:src="@drawable/image" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
Run Code Online (Sandbox Code Playgroud)