【问题标题】:PercentageRelativeLayout left margin is incorrect百分比相对布局左边距不正确
【发布时间】:2016-03-30 15:41:05
【问题描述】:

我的按钮被推到左边太多(分别不是 33% 和 66%,第一个按钮也不是 50%): Screenshot

这也发生在模拟器中。我目前正在 OnePlus One 上对此进行测试。

这里是 PercentageRelativeLayout 部分:

<android.support.percent.PercentRelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/textView"
        android:layout_above="@+id/contactText">

        <Button
            app:layout_widthPercent="30%"
            app:layout_heightPercent="20%"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/round_button"
            android:text="Σουβλακι"
            android:textColor="#fff"
            android:id="@+id/souvlakiButton"
            app:layout_marginTopPercent="0%"
            app:layout_marginLeftPercent="33%"/>

        <Button
            app:layout_widthPercent="30%"
            app:layout_heightPercent="20%"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/round_button"
            android:text="Burger"
            android:textColor="#fff"
            android:id="@+id/burgerButton"
            app:layout_marginTopPercent="66%"
            app:layout_marginLeftPercent="33%"/>

        <Button
            app:layout_widthPercent="30%"
            app:layout_heightPercent="20%"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/round_button"
            android:text="Pizza"
            android:textColor="#fff"
            android:id="@+id/pizzaButton"
            app:layout_marginTopPercent="0%"
            app:layout_marginLeftPercent="66%"/>

        <Button
            app:layout_widthPercent="30%"
            app:layout_heightPercent="20%"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/round_button"
            android:text="Κρέπα"
            android:textColor="#fff"
            android:id="@+id/pancakeButton"
            app:layout_marginTopPercent="66%"
            app:layout_marginLeftPercent="66%"/>

        <Button
            app:layout_widthPercent="30%"
            app:layout_heightPercent="20%"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/round_button"
            android:text="Καφές"
            android:textColor="#fff"
            android:id="@+id/coffeeButton"
            app:layout_marginTopPercent="33%"
            app:layout_marginLeftPercent="50%" />

        </android.support.percent.PercentRelativeLayout>

我还将这个项目保存在Github。如何解决我的问题?我也在尝试使用圆形控件,但我想这是不可能的,有时它们会是椭圆形的。

【问题讨论】:

    标签: android android-studio material-design androiddesignsupport android-percent-library


    【解决方案1】:

    如果您希望coffeButton 水平居中,则在设置边距时应考虑按钮宽度。由于按钮的宽度为 30%,要居中它需要 app:layout_marginLeftPercent50% - 30% / 2 = 35%

    上边距app:layout_marginTopPercent33% - 20% / 2 = 23%

    其他按钮也是如此。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-06-01
      • 2016-10-19
      • 2013-11-23
      • 2012-08-11
      • 1970-01-01
      • 2012-10-12
      • 1970-01-01
      相关资源
      最近更新 更多