【问题标题】:SegmentedGroup - last button is squeezedSegmentedGroup - 最后一个按钮被挤压
【发布时间】:2017-09-28 15:23:54
【问题描述】:

我正在使用来自https://github.com/Kaopiz/android-segmented-control 的分段控制,它工作得很好,除了最后一个按钮总是像这样被挤压:

我正在使用简单布局动态添加 RadioButtons:

<RadioButton xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    style="@style/RadioButton" />

我尝试了 Layout_width="wrap content" 和删除 "layout_weight" 等变体 - 结果相同。 分段控件本身的父布局也没有给出任何提示:

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:background="@color/white"
        android:gravity="center"
        android:minHeight="60dp">

        <info.hoang8f.android.segmented.SegmentedGroup
            android:id="@+id/segmentedGroup"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            segmentedgroup:sc_border_width="1dp"
            segmentedgroup:sc_corner_radius="10dp"
            segmentedgroup:sc_tint_color="#FFEB3B">


        </info.hoang8f.android.segmented.SegmentedGroup>
    </RelativeLayout>

【问题讨论】:

    标签: android radio-group android-radiogroup segmentedcontrol


    【解决方案1】:

    偶然发现这个话题的答案:Programmatically-added RadioButtons refuse to obey LayoutParams weighting

    在将 Button 添加到 RadioGroup 之前以编程方式设置布局参数即可达到预期效果:

      RadioGroup.LayoutParams layoutParams = new RadioGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1f);
        radioButton.setLayoutParams(layoutParams);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-26
      • 2016-12-29
      • 2021-09-05
      相关资源
      最近更新 更多