是否真的不可能在Android GridLayout中轻松强制相等的列宽?尝试明显的布局......
<GridLayout 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:columnCount="4"
android:rowCount="8"
tools:context=".MainActivity" >
<Button
android:id="@+id/button1"
android:layout_gravity="center"
android:text="Button 1" />
<Button
android:id="@+id/button2"
android:layout_gravity="center"
android:text="Button 2" />
<Button
android:id="@+id/button3"
android:layout_gravity="center"
android:text="Button 3" />
<Button
android:id="@+id/button4"
android:layout_gravity="center"
android:text="Button 4" />
</GridLayout>
Run Code Online (Sandbox Code Playgroud)
...将最右边的按钮放在一个明显比其他三个更宽的列中.(使用按钮文本播放,您可以轻松获得更糟糕的示例.)
我阅读了有关GridLayouts中空间分布过多的Android文档,但看起来很明显甚至列宽也经常(任何可能甚至是典型的)在这样的情况下需要我不得不相信我遗漏了一些明显/容易的东西.
我正在编写一个 Android AppWidget。小部件的布局包含一个 LinearLayout 和其中的许多 ImageView。在 AppWidgetProvider OnUpdate 方法中,我首先为布局创建一个 RemoteViews ...
var rv = new RemoteViews(context.PackageName, Resource.Layout.WidgetLayout);
Run Code Online (Sandbox Code Playgroud)
...并且,使用它,我可以为每个子 ImageView 设置位图。
然而,我真正想做的是在布局完成后获取 ImageView 的实际大小,以便我可以在其中绘制精确大小的图像(可能通过位图)。我看不出有什么方法可以通过 RemoteViews 获取 ImageView 大小,也没有任何方法可以获取 RemoteViews 项目的底层 ImageView。
我能做到这一点吗?是在OnUpdate()中完成的吗?如果是这样,怎么办?如果没有,我应该在哪里做?
提前致谢。