Skip to content
This repository was archived by the owner on Jun 27, 2020. It is now read-only.

Commit 0a1d757

Browse files
author
Evgeniy Kanivets
committed
Fixed bug with different sizes of dialog and its view
1 parent 92736a0 commit 0a1d757

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

app/src/main/java/com/blogspot/e_kanivets/moneytracker/ui/AddExpenseDialog.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ public void onClick(View v) {
8686
public void onShow(DialogInterface dialog) {
8787
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
8888
imm.showSoftInput(findViewById(R.id.et_title), InputMethodManager.SHOW_IMPLICIT);
89+
90+
//Set width of dialog to match a width of content
91+
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
92+
getWindow().setLayout(Math.min(metrics.widthPixels-20, AppUtils.scaleValue(context, 700)), LinearLayout.LayoutParams.WRAP_CONTENT);
93+
getWindow().setGravity(Gravity.CENTER_HORIZONTAL);
8994
}
9095
});
9196
}

app/src/main/java/com/blogspot/e_kanivets/moneytracker/ui/AddIncomeDialog.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ public void onClick(View v) {
8686
public void onShow(DialogInterface dialog) {
8787
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
8888
imm.showSoftInput(findViewById(R.id.et_title), InputMethodManager.SHOW_IMPLICIT);
89+
90+
//Set width of dialog to match a width of content
91+
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
92+
getWindow().setLayout(Math.min(metrics.widthPixels-20, AppUtils.scaleValue(context, 700)), LinearLayout.LayoutParams.WRAP_CONTENT);
93+
getWindow().setGravity(Gravity.CENTER_HORIZONTAL);
8994
}
9095
});
9196
}

app/src/main/res/layout/dialog_add_record.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22

33
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
4-
android:orientation="vertical" android:layout_width="350dp"
4+
android:orientation="vertical" android:layout_width="match_parent"
55
android:layout_height="wrap_content"
66
android:background="@color/white"
77
android:layout_gravity="center">

0 commit comments

Comments
 (0)