gpt4 book ai didi

android - 支持库中的 GridLayout 在 API 16-17 上无法正常工作

转载 作者:搜寻专家 更新时间:2023-11-01 08:42:18 25 4
gpt4 key购买 nike

我需要创建类似计算器键盘的东西。 GridLayout 是它的理想选择(而且仅适用于它 :))。所以,我使用支持库中的那个(compile 'com.android.support:gridlayout-v7:22.2.0'。这是我的 xml:

<android.support.v7.widget.GridLayout
android:layout_width="match_parent"
android:layout_height="0dp"
app:columnCount="4"
app:rowCount="4"
android:layout_gravity="bottom"
android:layout_weight="4"
app:alignmentMode="alignBounds"
app:rowOrderPreserved="false"
app:orientation="horizontal">

<Button android:text="7"
android:id="@+id/button7"
app:layout_columnWeight="1"
app:layout_rowWeight="1"
style="@style/CalculatorButton"/>
<Button android:text="8"
android:id="@+id/button8"
app:layout_columnWeight="1"
app:layout_rowWeight="1"
style="@style/CalculatorButton"/>
<Button android:text="9"
android:id="@+id/button9"
app:layout_columnWeight="1"
app:layout_rowWeight="1"
style="@style/CalculatorButton"/>
<Button android:text="←"
android:id="@+id/button_backspace"
app:layout_columnWeight="1"
app:layout_rowWeight="1"
style="@style/CalculatorButton"/>

<Button android:text="4"
android:id="@+id/button4"
app:layout_columnWeight="1"
app:layout_rowWeight="1"
style="@style/CalculatorButton"/>
<Button android:text="5"
android:id="@+id/button5"
app:layout_columnWeight="1"
app:layout_rowWeight="1"
style="@style/CalculatorButton"/>
<Button android:text="6"
android:id="@+id/button6"
app:layout_columnWeight="1"
app:layout_rowWeight="1"
style="@style/CalculatorButton"/>
<Button android:text="@string/clean"
android:id="@+id/button_clear"
app:layout_columnWeight="1"
app:layout_rowWeight="1"
style="@style/CalculatorButton"/>

<Button android:text="1"
android:id="@+id/button1"
app:layout_columnWeight="1"
app:layout_rowWeight="1"
style="@style/CalculatorButton"/>
<Button android:text="2"
android:id="@+id/button2"
app:layout_columnWeight="1"
app:layout_rowWeight="1"
style="@style/CalculatorButton"/>
<Button android:text="3"
android:id="@+id/button3"
app:layout_columnWeight="1"
app:layout_rowWeight="1"
style="@style/CalculatorButton"/>
<Button
android:id="@+id/button_clear_all"
app:layout_columnWeight="1"
app:layout_rowWeight="1"
app:layout_gravity="fill_vertical"
android:text="@string/clean_all"
app:layout_rowSpan="2"
android:background="@color/calculator_button_separator_color"
android:textColor="@drawable/light_button_text_color"
style="@style/CalculatorButton"/>

<Button
android:id="@+id/button0"
app:layout_columnWeight="1"
app:layout_rowWeight="1"
app:layout_gravity="fill_horizontal"
android:text="0"
app:layout_columnSpan="2"
style="@style/CalculatorButton"/>
<Button android:text="."
android:id="@+id/button_dot"
app:layout_columnWeight="1"
app:layout_rowWeight="1"
style="@style/CalculatorButton"/>

</android.support.v7.widget.GridLayout>

在 Android 4.3-4.4 上一切正常:

但是在Android 4.1-4.2上有问题:

所以,我不明白我的问题在哪里。

最佳答案

嗯,这确实是支持库中的错误。我将 compile 'com.android.support:gridlayout-v7:22.2.0' 替换为 compile 'com.android.support:gridlayout-v7:22.0.+',用代码做了一些魔术,检查了 4.1 和 4.3,现在它是工作!

<android.support.v7.widget.GridLayout
android:layout_width="match_parent"
android:layout_height="0dp"
app:columnCount="4"
app:rowCount="4"
android:layout_gravity="bottom"
android:layout_weight="4"
app:alignmentMode="alignBounds"
app:orientation="horizontal">

<Button android:text="7"
android:id="@+id/button7"
app:layout_gravity="fill"
app:layout_columnWeight="1"
app:layout_rowWeight="1"
style="@style/CalculatorButton"/>
<Button android:text="8"
android:id="@+id/button8"
app:layout_gravity="fill"
app:layout_columnWeight="1"
app:layout_rowWeight="1"
style="@style/CalculatorButton"/>
<Button android:text="9"
android:id="@+id/button9"
app:layout_gravity="fill"
app:layout_columnWeight="1"
app:layout_rowWeight="1"
style="@style/CalculatorButton"/>
<Button android:text="←"
android:id="@+id/button_backspace"
app:layout_columnWeight="1"
app:layout_gravity="fill"
app:layout_rowWeight="1"
style="@style/CalculatorButton"/>

<Button android:text="4"
android:id="@+id/button4"
app:layout_columnWeight="1"
app:layout_gravity="fill"
app:layout_rowWeight="1"
style="@style/CalculatorButton"/>
<Button android:text="5"
android:id="@+id/button5"
app:layout_columnWeight="1"
app:layout_gravity="fill"
app:layout_rowWeight="1"
style="@style/CalculatorButton"/>
<Button android:text="6"
android:id="@+id/button6"
app:layout_columnWeight="1"
app:layout_gravity="fill"
app:layout_rowWeight="1"
style="@style/CalculatorButton"/>
<Button android:text="@string/clean"
app:layout_gravity="fill"
android:id="@+id/button_clear"
app:layout_columnWeight="1"
app:layout_rowWeight="1"
style="@style/CalculatorButton"/>

<Button android:text="1"
android:id="@+id/button1"
app:layout_columnWeight="1"
app:layout_gravity="fill"
app:layout_rowWeight="1"
style="@style/CalculatorButton"/>
<Button android:text="2"
android:id="@+id/button2"
app:layout_columnWeight="1"
app:layout_gravity="fill"
app:layout_rowWeight="1"
style="@style/CalculatorButton"/>
<Button android:text="3"
android:id="@+id/button3"
app:layout_columnWeight="1"
app:layout_rowWeight="1"
app:layout_gravity="fill"
style="@style/CalculatorButton"/>
<Button
android:id="@+id/button_clear_all"
app:layout_columnWeight="1"
app:layout_rowWeight="1"
app:layout_gravity="fill"
android:text="@string/clean_all"
app:layout_rowSpan="2"
android:background="@color/calculator_button_separator_color"
android:textColor="@drawable/light_button_text_color"
style="@style/CalculatorButton"/>

<Button
android:id="@+id/button0"
app:layout_columnWeight="1"
app:layout_rowWeight="1"
app:layout_gravity="fill"
android:text="0"
app:layout_columnSpan="2"
style="@style/CalculatorButton"/>
<Button android:text="."
android:id="@+id/button_dot"
app:layout_gravity="fill"
app:layout_columnWeight="1"
app:layout_rowWeight="1"
style="@style/CalculatorButton"/>
</android.support.v7.widget.GridLayout>

关于android - 支持库中的 GridLayout 在 API 16-17 上无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31377357/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com