Leo*_*rak 9 android android-layout
我LinearLayout用TextView,GridLayout而另一个TextView.它可以在许多现代手机和平板电脑上正确显示,但在像Nexus S这样的小型显示屏上完全失败.请参阅下面的图片.
我试图减小字体大小,删除9补丁背景,甚至删除所有边距.当有一些边缘时,我只能看到digit7.然后我最小化了它们,我可以看到第一个按钮的四行,它是渲染的两倍.我不明白为什么,它应该有wrap_content宽度.
我试图最小化代码并将其缩小为GridLayout单行,但仍然不适合屏幕的宽度.
那里发生了什么?
更新:
更新2:
当字体为38sp或更大时,Nexus 5x也有同样的问题.有趣的是,Studio的设计器显示正确的布局,但设备/模拟器都显示损坏的视图和跟随错误:
D/android.support.v7.widget.GridLayout: vertical constraints: y1-y0>=197, y2-y1>=197, y3-y2>=197, y4-y3>=197, y4-y0<=785 are inconsistent; permanently removing: y4-y0<=785.
Run Code Online (Sandbox Code Playgroud)
calc.xml:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!--Display row-->
<TextView
android:id="@+id/assignment"
android:text="50 + 40 = 90"
style="@style/Formula"
android:focusable="false"
android:layout_width="match_parent"
android:layout_height="80dp"
tools:ignore="HardcodedText" />
<android.support.v7.widget.GridLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
app:columnCount="4"
app:rowCount="4">
<!-- row with 7-9,+ -->
<Button
android:id="@+id/digit7"
android:text="7"
style="@style/KeypadLeftButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:layout_rowWeight="1"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/digit8"
android:text="8"
style="@style/KeypadButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:layout_rowWeight="1"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/digit9"
android:text="9"
style="@style/KeypadButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:layout_rowWeight="1"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/buttonPlus"
android:text="+"
style="@style/KeypadRightButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_rowWeight="0.5"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
<!--row with 4-6, - -->
<Button
android:id="@+id/digit4"
android:text="4"
style="@style/KeypadLeftButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:layout_rowWeight="1"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/digit5"
android:text="5"
style="@style/KeypadButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:layout_rowWeight="1"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/digit6"
android:text="6"
style="@style/KeypadButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:layout_rowWeight="1"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/buttonMinus"
android:text="-"
style="@style/KeypadRightButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_rowWeight="0.5"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
<!--row with 1-3, * -->
<Button
android:id="@+id/digit1"
android:text="1"
style="@style/KeypadLeftButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:layout_rowWeight="1"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/digit2"
android:text="2"
style="@style/KeypadButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:layout_rowWeight="1"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/digit3"
android:text="3"
style="@style/KeypadButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:layout_rowWeight="1"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/buttonMultiply"
android:text="\u22C5"
style="@style/KeypadRightButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_rowWeight="0.5"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
<!--row with 0, backspace and / -->
<Button
android:id="@+id/digit0"
android:text="0"
style="@style/KeypadLeftButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_columnWeight="1"
app:layout_gravity="fill_horizontal"
app:layout_rowWeight="1"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/buttonBackspace"
android:text="?"
style="@style/KeypadButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_gravity="fill_vertical"
app:layout_columnSpan="2"
app:layout_rowWeight="0.5"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/buttonDivide"
android:text=":"
style="@style/KeypadRightButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_rowWeight="0.5"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
</android.support.v7.widget.GridLayout>
<!--row with button submit -->
<Button
android:id="@+id/buttonSubmit"
android:text="@string/action_next_formula"
style="@style/KeypadNextButton"
android:layout_width="match_parent"
android:layout_height="80dp"
app:layout_gravity="fill_horizontal"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
款式:
<style name="Formula">
<item name="android:textSize">@dimen/calc_button_text</item>
<item name="android:textColor">@color/gray_35</item>
<item name="android:gravity">center</item>
<item name="android:background">@drawable/lcd</item>
<item name="android:layout_marginTop">@dimen/calc_big_margin</item>
<item name="android:layout_marginBottom">@dimen/calc_superbig_margin</item>
<item name="android:layout_marginLeft">@dimen/calc_big_margin</item>
<item name="android:layout_marginRight">@dimen/calc_big_margin</item>
</style>
<style name="KeypadButton" parent="@style/Widget.AppCompat.Button">
<item name="android:textSize">@dimen/calc_button_text</item>
<item name="android:textColor">@color/white</item>
<!--<item name="android:background">@drawable/tl_2</item>-->
<item name="android:layout_marginLeft">@dimen/calc_small_margin</item>
<item name="android:layout_marginBottom">@dimen/calc_small_margin</item>
</style>
<style name="KeypadLeftButton" parent="@style/KeypadButton">
<item name="android:layout_marginLeft">@dimen/calc_big_margin</item>
</style>
<style name="KeypadRightButton" parent="@style/KeypadButton">
<item name="android:layout_marginRight">@dimen/calc_big_margin</item>
</style>
<style name="KeypadNextButton" parent="@style/Widget.AppCompat.Button.Colored">
<item name="android:background">@drawable/tl_next</item>
<item name="android:textSize">@dimen/calc_button_text</item>
<item name="android:layout_marginTop">@dimen/calc_big_margin</item>
<item name="android:layout_marginBottom">@dimen/calc_big_margin</item>
<item name="android:layout_marginLeft">@dimen/calc_big_margin</item>
<item name="android:layout_marginRight">@dimen/calc_big_margin</item>
</style>
Run Code Online (Sandbox Code Playgroud)
梦诗:
<dimen name="calc_button_text">14sp</dimen>
<dimen name="calc_superbig_margin">2dp</dimen>
<dimen name="calc_big_margin">1dp</dimen>
<dimen name="calc_small_margin">0dp</dimen>
Run Code Online (Sandbox Code Playgroud)
更新16日
Manjunath Prabhakar说,麻烦可能与体重有关.所以我试图删除所有权重属性,现在布局更有意义.我还没修好它.我会考虑将布局重写为嵌套的LinearLayouts作为后退,因此我会为其他建议提供赏金.
我想这是支持版本的bug GridLayout.
看看这个(目前是Assigned):我认为这与你关于Nexus 5X字体大小行为的问题有关.一般来说,我在这里发现了很多相关的错误(与GridLayout宽度测量有关).
我会尝试给你一个解决方法.
我正在使用com.android.support:gridlayout-v7:25.1.1.
我认为您可以通过这种方式解决您的布局问题(旧手机中的对齐和Nexus 5X中的字体大小):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!--Display row-->
<TextView
android:id="@+id/assignment"
android:text="50 + 40 = 90"
style="@style/Formula"
android:focusable="false"
android:layout_width="match_parent"
android:layout_height="80dp"
tools:ignore="HardcodedText" />
<android.support.v7.widget.GridLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
app:columnCount="4"
app:rowCount="4">
<!-- row with 7-9,+ -->
<LinearLayout
app:layout_gravity="fill_horizontal"
app:layout_columnSpan="4"
android:orientation="horizontal"
app:layout_rowWeight="1">
<Button
android:id="@+id/digit7"
android:text="7"
style="@style/KeypadLeftButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
app:layout_rowWeight="1"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/digit8"
android:text="8"
style="@style/KeypadButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
app:layout_rowWeight="1"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/digit9"
android:text="9"
style="@style/KeypadButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
app:layout_rowWeight="1"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/buttonPlus"
android:text="+"
style="@style/KeypadRightButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:layout_rowWeight="0.5"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
</LinearLayout>
<!--row with 4-6, - -->
<LinearLayout
app:layout_gravity="fill_horizontal"
app:layout_columnSpan="4"
android:orientation="horizontal"
app:layout_rowWeight="1">
<Button
android:id="@+id/digit4"
android:text="4"
style="@style/KeypadLeftButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
app:layout_rowWeight="1"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/digit5"
android:text="5"
style="@style/KeypadButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
app:layout_rowWeight="1"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/digit6"
android:text="6"
style="@style/KeypadButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
app:layout_rowWeight="1"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/buttonMinus"
android:text="-"
style="@style/KeypadRightButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:layout_rowWeight="0.5"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
</LinearLayout>
<!--row with 1-3, * -->
<LinearLayout
app:layout_gravity="fill_horizontal"
app:layout_columnSpan="4"
android:orientation="horizontal"
app:layout_rowWeight="1">
<Button
android:id="@+id/digit1"
android:text="1"
style="@style/KeypadLeftButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
app:layout_rowWeight="1"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/digit2"
android:text="2"
style="@style/KeypadButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
app:layout_rowWeight="1"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/digit3"
android:text="3"
style="@style/KeypadButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
app:layout_rowWeight="1"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/buttonMultiply"
android:text="\u22C5"
style="@style/KeypadRightButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:layout_rowWeight="0.5"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
</LinearLayout>
<!--row with 0, backspace and / -->
<LinearLayout
app:layout_gravity="fill_horizontal"
app:layout_columnSpan="4"
android:orientation="horizontal"
app:layout_rowWeight="1"
android:weightSum="4">
<Button
android:id="@+id/digit0"
android:text="0"
style="@style/KeypadLeftButton"
android:layout_width="0dp"
android:layout_height="match_parent"
app:layout_columnWeight="1"
app:layout_gravity="fill_horizontal"
app:layout_rowWeight="1"
tools:ignore="HardcodedText"
android:layout_weight="1"/>
<Button
android:id="@+id/buttonBackspace"
android:text="?"
style="@style/KeypadButton"
android:layout_width="0dp"
android:layout_height="match_parent"
app:layout_gravity="fill_vertical"
app:layout_columnSpan="2"
app:layout_rowWeight="0.5"
app:layout_columnWeight="1"
tools:ignore="HardcodedText"
android:layout_weight="2"/>
<Button
android:id="@+id/buttonDivide"
android:text=":"
style="@style/KeypadRightButton"
android:layout_width="0dp"
android:layout_height="match_parent"
app:layout_rowWeight="0.5"
app:layout_columnWeight="1"
tools:ignore="HardcodedText"
android:layout_weight="1"/>
</LinearLayout>
</android.support.v7.widget.GridLayout>
<!--row with button submit -->
<Button
android:id="@+id/buttonSubmit"
android:text="NEXT"
style="@style/KeypadNextButton"
android:layout_width="match_parent"
android:layout_height="80dp"
app:layout_gravity="fill_horizontal"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
基本上,我所做的是将每组按钮(除了最后一行之外的四个按钮)包装在一个LinearLayout.
在这里你可以看到它在两部手机中的外观:
如您所见,最后一行的对齐存在问题.我认为你可以尝试解决这些按钮与属性和属性的对齐.如果您想在最后一个主题中进一步改进,请告诉我.
希望这可以帮助.
| 归档时间: |
|
| 查看次数: |
826 次 |
| 最近记录: |