[英]AppCompatButton's height is different on devices?
I'm working with AppCompatButton and face with a problem. 我正在使用AppCompatButton并遇到问题。 The height of button is different on some tested device.
某些测试设备上的按钮高度不同。
For example: 例如:
on SamSung Galaxy Note 4: 在SamSung Galaxy注4:
on Nexus 6: 在Nexus 6上:
I defined my button as the following:
我将我的按钮定义如下:
<android.support.v7.widget.AppCompatButton
android:id="@+id/btn_add_to_cart"
android:layout_width="0dp"
android:layout_height="55dp"
android:layout_weight="5"
android:text="Add to cart"
android:textAllCaps="false"/>
I don't know why my button are different between devices. 我不知道为什么我的按钮在设备之间有所不同。 Please help me to fix this.
请帮我解决这个问题。
Thanks in advance. 提前致谢。
I had a similar issue when trying to align button shadows (done by elevation). 尝试对齐按钮阴影(由高程完成)时,我遇到了类似的问题。 The default style for a Material button on some Samsung devices does not set the elevation or the stateListAnimator.
某些Samsung设备上“材质”按钮的默认样式不设置高程或stateListAnimator。 Try setting android:stateListAnimator for your button to sth like this:
尝试为你的按钮设置android:stateListAnimator,如下所示:
<selector xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:state_enabled="true">
<set>
<objectAnimator android:propertyName="translationZ"
android:duration="100"
android:valueTo="1dp"
android:valueType="floatType"/>
<objectAnimator android:propertyName="elevation"
android:duration="0"
android:valueTo="2dp"
android:valueType="floatType"/>
</set>
</item>
<!-- base state -->
<item android:state_enabled="true">
<set>
<objectAnimator android:propertyName="translationZ"
android:duration="100"
android:valueTo="0"
android:startDelay="100"
android:valueType="floatType"
tools:targetApi="kitkat" />
<objectAnimator android:propertyName="elevation"
android:duration="0"
android:valueTo="2dp"
android:valueType="floatType" />
</set>
</item>
<item>
<set>
<objectAnimator android:propertyName="translationZ"
android:duration="0"
android:valueTo="0"
android:valueType="floatType"/>
<objectAnimator android:propertyName="elevation"
android:duration="0"
android:valueTo="0"
android:valueType="floatType"/>
</set>
</item>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.