我有一个LinearLayout
用来制作一个显示日期的框:
<LinearLayout android:id="@+id/date_layout"
android:background="@drawable/bg_frame"
android:layout_gravity="center"
android:layout_marginRight="3dp"
android:layout_rowSpan="3"
android:minWidth="65dp"
android:orientation="vertical"
>
<TextView android:id="@+id/date"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:textColor="@android:color/holo_blue_bright"
android:textSize="20sp"
/>
<View
android:background="@android:color/holo_blue_bright"
android:layout_height="1dp"
android:layout_width="match_parent"
/>
<TextView android:id="@+id/day_of_week"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:textColor="@android:color/holo_blue_bright"
/>
</LinearLayout>
它是一个不错的小盒子(View
上面的代码中没有这个):
当我把View
它放在那里时,它把盒子一直延伸到屏幕上,我只想在盒子的宽度上画一条线而不改变它的宽度,为什么它在我编码的时候不起作用?不应该android:layout_width="match_parent"
简单地匹配包含的宽度LinearLayout
吗?为什么它适用于两者TextViews
而不是View
?
LinearLayout
包含在一个GridLayout
.
我还发现,如果我将 替换为View
,TextView
但其他所有内容完全相同,它会按我的意愿工作,并且不会扩展以填充整个屏幕宽度。为什么 TextView 像我期望的那样工作而 View 不是?