0

我有一个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.

我还发现,如果我将 替换为ViewTextView但其他所有内容完全相同,它会按我的意愿工作,并且不会扩展以填充整个屏幕宽度。为什么 TextView 像我期望的那样工作而 View 不是?

4

1 回答 1

0

你在 LinearLayout 上没有 layout_width 或 layout_height。所以它的宽度和高度是未定义的,可能默认为全屏。您需要将其宽度设置为 wrap_content。

于 2013-01-30T19:42:43.873 回答