按钮未在TableRow中正确显示

时间:2016-12-29 05:45:53

标签: android layout

我是以编程方式在Button中添加TableRow。当我添加按钮时,按钮显示我想要的位置,除了它看起来按钮向下移动。我希望按钮居中对齐。以下是我如何将表格行添加到表格行,使用表格行添加xml,以及运行应用程序时按钮的外观图片

enter image description here

    public void addNewButtonToRegister(String buttonString, String buttonPrice, Button_Sizes buttonSize){
    Button newButton = new Button(getActivity().getApplicationContext());
    Button addButton = (Button) mMenuFragment.findViewById(R.id.add_button);
    int height = addButton.getHeight();
    int width = addButton.getWidth();
    newButton.setLayoutParams(new TableRow.LayoutParams(height, width));
    newButton.setText(buttonString + "\n" + buttonPrice);
    TableRow firstRow = (TableRow) mMenuFragment.findViewById(R.id.first_row);
    firstRow.addView(newButton);
}

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="vertical"
          android:padding="@dimen/activity_vertical_margin"
          android:layout_width="match_parent"
          android:id="@+id/test"
          android:layout_height="match_parent">

<TableLayout
    android:id="@+id/table_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TableRow
        android:orientation="horizontal"
        android:id="@+id/first_row">

        <Button
            android:id="@+id/add_button"
            android:text="@string/add_button"
            android:textSize="30dp"
            android:layout_width="@dimen/register_button_size"
            android:layout_height="@dimen/register_button_size"/>



    </TableRow>

</TableLayout>

1 个答案:

答案 0 :(得分:0)

尝试此代码,我根据重量概念设计并根据您的意愿进行修改

df1[['A', 'B', 'C', 'E']] == df2.values

      A     B     C     E
0  True  True  True  True