0

Есть кастомный диалог с таблицей

введите сюда описание изображения

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffffff">

<ImageView
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:id="@+id/dialog_card_image_head"
    android:gravity="center"
    android:background="#DA5F6A"

    android:scaleType="fitCenter" />

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:gravity="center"
    android:layout_height="wrap_content"
    >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TEXTO"
    android:id="@+id/text_dialog"
    android:layout_marginTop="20dp"
    android:layout_marginLeft="4dp"
    android:layout_marginRight="4dp"
    android:layout_marginBottom="20dp"
    android:textSize="18sp"
    android:textColor="#ff000000"

     />
    </LinearLayout>
<LinearLayout
    android:orientation="vertical"
    android:layout_width="wrap_content"

    android:gravity="center"
    android:layout_height="wrap_content"
    >
<TableLayout
    android:layout_below="@+id/text_dialog"
    android:layout_marginTop="10dp"
    android:layout_marginBottom="10dp"

    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:stretchColumns="1"

    android:id="@+id/dialog_table">
</TableLayout>

    </LinearLayout>
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="OK"
    android:id="@+id/btn_dialog"
    android:gravity="center_vertical|center_horizontal"
    android:layout_below="@+id/dialog_table"
    android:layout_marginBottom="20dp"

    android:layout_centerHorizontal="true"
    android:textColor="#ffffffff" />

</LinearLayout>

вызываю так

public void showDialog(Activity activity, String msg, int res){
        final Dialog dialog = new Dialog(activity);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setCancelable(false);
        dialog.setContentView(R.layout.dialog_card);



        ImageView head = (ImageView) dialog.findViewById(R.id.dialog_card_image_head);
        head.setImageResource(res);

        TextView text = (TextView) dialog.findViewById(R.id.text_dialog);
        text.setText(msg);

        TableLayout tableLayout = (TableLayout)dialog.findViewById(R.id.dialog_table);

        int BOOKSHELF_ROWS = 7;
        int BOOKSHELF_COLUMNS = 2;
        String [][] test_table = {{"Зал","а"},{"Номер","0550276"},{"Заглавие","\tСхемотехника: учебное пособие для вузов (направ. 220200 (651900) \"Автоматизация и управление\")"}
                ,{"Автор","Чье"},{"Дата выдачи","23.05.2016"},{"Срок","01.08.2016"},{"Долг (дней)","308"}};


        for (int i = 0; i < BOOKSHELF_ROWS; i++) {

            TableRow tableRow = new TableRow(getActivity());
            tableRow.setLayoutParams(new LinearLayout.LayoutParams
                    (LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));

            tableLayout.setStretchAllColumns(true);


            for (int j = 0; j < BOOKSHELF_COLUMNS; j++) {
                TextView highsLabel = new TextView(getActivity());
                highsLabel.setText(test_table[i][j]);
                highsLabel.setTypeface(Typeface.DEFAULT_BOLD);


                tableRow.addView(highsLabel, j);
            }

            tableLayout.addView(tableRow, i);
        }

        Button dialogButton = (Button) dialog.findViewById(R.id.btn_dialog);
        dialogButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });

        dialog.show();

    }
}

Заглавие уходит за рамки. как такое исправить?

1 ответ 1

0

Добавьте отступ в главый LinearLayout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:padding="16dp" <<==
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffffff">
5
  • заглавие это поле в таблице а не шапка 5 июн 2017 в 8:48
  • не помогло, такая же проблема 5 июн 2017 в 8:50
  • А если padding на margin заменить?
    – McDaggen
    5 июн 2017 в 19:10
  • не помогло, все тоже самое 6 июн 2017 в 1:43
  • Не понятно как у вас за пределами LinearLayout Button находится, это полный код разметки?
    – McDaggen
    6 июн 2017 в 5:46

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.