Android:如何制作square 1:1小部件
我想做一个squaere小部件 我的布局:Android:如何制作square 1:1小部件,android,android-layout,android-widget,android-appwidget,Android,Android Layout,Android Widget,Android Appwidget,我想做一个squaere小部件 我的布局: <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/backgroundImageView"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/backgroundImageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:focusable="false"
android:scaleType="fitXY"
android:src="@drawable/rounded_conners"/>
<ImageButton
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:background="@drawable/transparent_color"
android:clickable="true"
android:focusable="true"
android:padding="8dp"
android:scaleType="fitCenter"
android:src="@drawable/btn03_off" />
</FrameLayout>
我可以把按钮做成正方形。感谢scr中的方形图像,但我需要的是一个背景图像视图是方形布局(纵横比1:1),并且我的形状不是方形。通过对图像视图进行子类化并在其中调用teh onmeasure(),使图像视图成为方形。你是对的,AppWidgets无法利用自定义视图。很抱歉,这是我无法解决的问题…为什么不通过编程设置make square,使用相同的值调用
setWidth
和setHeight
?你试过了吗?这个小部件是“可扩展的”,所以用户实际上可以在屏幕上改变它的尺寸。。不幸的是,我不知道具体的维度。我不确定是否可以在小部件中使用设置的宽度和高度