我为人人“的最小宽度”,我使用的按钮大小的倍数dimens.xml文件。而且我也有多个版本的主版面和按钮版面(用于多屏支持)。添加按钮的LinearLayout程序不能正常工作
我想插入多个按钮进入布局编程,并与XML布局夸大这个按钮。
这是怎么做到这一点:
Button temp_button = null;
final LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
for(int i = 0; i < 7; i++) {
temp_button = (Button)inflater.inflate(R.layout.answer_letter_button, null);
temp_button.setTextColor(accent_color);
answer_letters.add(temp_button);
answer_panel.addView(answer_letters.get(i));
}
这是这些按钮父布局:
<LinearLayout
android:id="@+id/answer_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
app:layout_constraintBottom_toTopOf="@+id/letter_panel">
</LinearLayout>
和按键布局:
<Button
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="@dimen/answer_letter_button_size"
android:layout_height="@dimen/answer_letter_button_size"
android:text="M"
android:textStyle="bold"
android:textColor="@color/colorAccent"
android:textSize="@dimen/answer_letter_button_text_size"
android:layout_margin="@dimen/answer_letter_button_margin_size"
android:background="@drawable/shaped_button" />
我居然看到:
我在做什么错了,有人告诉我?
对不起,我错误地表达。 我的意思是,结果按钮的大小有问题。大部分都是一个按钮的宽度。
为什么要添加的按钮视图** answer_letters内部**第一,然后** ** answer_panel到? –
你正在这里运行一个循环,这就是为什么按钮显示在那里。 –