在入手安卓的时候,你是不是也有这样的苦恼,明明一样的代码,为啥在颜色view的颜色不显示,而LinearLayout中的背景颜色显示,你如果在哪里安卓颜色的取值类型就跑偏了,作为一个初学者,这不是我们应该考虑的,尝试看一下大小写,没错,View!上代码。
错误的:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_margin="16dp"
android:orientation="horizontal"
android:background="#000000"
android:padding="5dp">
<view
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@color/colorPrimary" />
<view
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#002233" />
</LinearLayout>
来!我们改成正确的:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_margin="16dp"
android:orientation="horizontal"
android:background="#000000"
android:padding="5dp">
<Viewiew
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@color/colorPrimary" />
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#002233" />
</LinearLayout>
我也是服了,其实这是很现实的问题,老师们一般不会犯这样低级的错误,就一带而过了,其实在我们输入v没给出提示的时候我们就应该发现猫腻,就是初学,不规范的地方太多,共勉啊!