0

我正在使用来自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>
4

1 回答 1

0

在这个主题上偶然找到的答案:Programmatically-added RadioButtons reject to obiuse LayoutParams weighting

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

  RadioGroup.LayoutParams layoutParams = new RadioGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1f);
    radioButton.setLayoutParams(layoutParams);
于 2017-10-02T08:49:00.507 回答