【发布时间】:2015-06-30 03:53:17
【问题描述】:
我正在尝试在我的 Android 应用中制作矩形块。我尝试使用 Shape Drawable 但它不起作用。 矩形.xml:
<?xml version="1.0" encoding="utf-8"?><shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="1dp"
android:color="#000000">
</stroke>
<solid android:color="#f0600000"/>
<size android:height="30dp" android:width="30dp"/></shape>
activity_main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="200dp"
android:layout_height="200dp" android:background="@android:color/holo_red_dark"
android:layout_centerInParent="true"
android:scaleType="center"
android:src="@drawable/rectangle">
</ImageView></RelativeLayout>
MainActivity.java 图像视图图像视图;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = (ImageView) findViewById(R.id.imageView);
setDrawable();
}
private void setDrawable(){
imageView.setImageResource(R.drawable.rectangle);
}
我在模拟器中看到的都是方形的,没有实心笔划。为什么不显示可绘制资源?谢谢
【问题讨论】:
-
通过将代码复制粘贴到新项目文件中解决。
标签: android xml shapedrawable