我想以编程方式向RadioGroup添加边距或填充但不起作用。
单选按钮:
<RadioButton xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_fruit"
android:button="@null"
android:checked="false" />
RadioGroup中:
<RadioGroup
android:id="@+id/radio_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:orientation="horizontal">
</RadioGroup>
Java代码:
RadioButton radioButtonView = (RadioButton) getActivity().getLayoutInflater().inflate(R.layout.radio_button, null);
radioGroup.addView(radioButtonView);
我尝试使用LayoutParams
和dividerPadding
,但它不起作用
答案 0 :(得分:9)
试试这个
CREATE OR REPLACE TRIGGER CREAT_SERVIÇO
BEFORE INSERT ON SERVIÇO
BEGIN
if((SELECT MORADA_RUA FROM SERVIÇO)=NULL and (SELECT LOCAIS_ID_LOCAL FROM SERVIÇO) = NULL) = TRUE
THEN
RAISE_APPLICATION_ERROR(-20000, 'YOU HAVE TO HAVE AN ADRESS OR AN LOCAL');
END IF;
END;
答案 1 :(得分:4)
保证金&amp;填充RadioButton:
RadioButton rd = new RadioButton(getActivity());
RadioGroup.LayoutParams params = new RadioGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.setMargins(left, top, right, bottom);
rd.setLayoutParams(params);
rd.setPadding(left, top, right, bottom);
radioGroup.addView(rd);
RadioGroup的边距和填充是相同的,只有LayoutParams的类型不同(不是RadioGroup.LayoutParams),但你的RadioGroup的父布局是什么:LinearLayout.LayoutParams或RelativeLayout.LayoutParams或FrameLayout.LayoutParams等你。明白了。
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.setMargins(left, top, right, bottom);
radioGroup.setLayoutParams(params);
左,上,右,下以像素为单位,因此您应将DP转换为PX,如此answer