【问题标题】:The sides of the buttons changed按钮的侧面发生了变化
【发布时间】:2017-12-20 03:46:25
【问题描述】:

当我在电脑上试用我的应用时,所有按钮都在正确的位置。

但是当我在手机上测试我的应用时,所有按钮都发生了变化。

我该如何解决这个问题?

这是我的 xml 代码:

<?xml version="1.0" encoding="utf-8"?>

<Space
    android:id="@+id/s1"
    android:layout_width="match_parent"
    android:layout_height="40dp"/>

<TextView
    android:id="@+id/tv"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/s1"
    android:textSize="30sp" />

<Space
    android:id="@+id/s2"
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:layout_below="@id/tv"/>

<LinearLayout
    android:id="@+id/ll789"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/s2"
    android:orientation="horizontal">

    <Button
        android:id="@+id/buttonSeven"
        style="@style/Widget.AppCompat.Button.Borderless"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="7"
        android:textSize="20sp" />

    <Button
        android:id="@+id/buttonEight"
        style="@style/Widget.AppCompat.Button.Borderless"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="8"
        android:textSize="20sp" />

    <Button
        android:id="@+id/buttonNine"
        style="@style/Widget.AppCompat.Button.Borderless"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="9"
        android:textSize="20sp" />

    <Button
        android:id="@+id/buttonDivide"
        style="@style/Widget.AppCompat.Button.Borderless"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="/"
        android:textSize="20sp" />

</LinearLayout>

<LinearLayout
    android:id="@+id/ll456"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/ll789"
    android:orientation="horizontal">

    <Button
        android:id="@+id/buttonFour"
        style="@style/Widget.AppCompat.Button.Borderless"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="4"
        android:textSize="20sp" />

    <Button
        android:id="@+id/buttonFive"
        style="@style/Widget.AppCompat.Button.Borderless"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="5"
        android:textSize="20sp" />

    <Button
        android:id="@+id/buttonSix"
        style="@style/Widget.AppCompat.Button.Borderless"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="6"
        android:textSize="20sp" />

    <Button
        android:id="@+id/buttonMultiply"
        style="@style/Widget.AppCompat.Button.Borderless"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="*"
        android:textSize="20sp" />

</LinearLayout>

<LinearLayout
    android:id="@+id/ll123"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/ll456"
    android:orientation="horizontal">

    <Button
        android:id="@+id/buttonOne"
        style="@style/Widget.AppCompat.Button.Borderless"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="1"
        android:textSize="20sp" />

    <Button
        android:id="@+id/buttonTwo"
        style="@style/Widget.AppCompat.Button.Borderless"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="2"
        android:textSize="20sp" />

    <Button
        android:id="@+id/buttonThree"
        style="@style/Widget.AppCompat.Button.Borderless"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="3"
        android:textSize="20sp" />

    <Button
        android:id="@+id/buttonSubtract"
        style="@style/Widget.AppCompat.Button.Borderless"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="-"
        android:textSize="20sp" />

</LinearLayout>

<LinearLayout
    android:id="@+id/ll0"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/ll123"
    android:orientation="horizontal">

    <Button
        android:id="@+id/buttonDot"
        style="@style/Widget.AppCompat.Button.Borderless"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="."
        android:textSize="20sp" />

    <Button
        android:id="@+id/buttonZero"
        style="@style/Widget.AppCompat.Button.Borderless"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="0"
        android:textSize="20sp" />

    <Button
        android:id="@+id/buttonEqual"
        style="@style/Widget.AppCompat.Button.Borderless"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="="
        android:textSize="20sp" />

    <Button
        android:id="@+id/buttonAdd"
        style="@style/Widget.AppCompat.Button.Borderless"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="+"
        android:textSize="20sp" />

</LinearLayout>

<LinearLayout
    android:id="@+id/llC"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/ll0"
    android:orientation="horizontal">

    <Space
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"/>

    <Space
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"/>

    <Space
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"/>

    <Button
        android:id="@+id/buttonClear"
        style="@style/Widget.AppCompat.Button.Borderless"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="C"
        android:textSize="20sp" />

</LinearLayout>

我想这可能是因为我的手机是希伯来语,我的电脑是英语。

【问题讨论】:

  • 您应该提供更多信息。这是如何编程的?我们能看到代码吗?您是否根据需要为任何样式添加前缀?
  • 您的手机是否设置为使用从右到左的语言/区域设置?

标签: android android-layout android-studio button android-linearlayout


【解决方案1】:

这很可能发生,因为您的 AndroidManifest.xml 文件中的 &lt;application&gt; 标记指定了 android:supportsRtl="true"。假设有这个属性,只要用户(即您)将他们的手机设置为从右到左的语言,您的LinearLayouts 的内容就会被反转。

您可以将此属性设置为false,或者您可以将android:layoutDirection="ltr" 添加到您的LinearLayouts。

【讨论】:

    猜你喜欢
    • 2013-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多