Extra space in AlertDialog
Opened this issue · 0 comments
illiaNaumov commented
Trying to nest DocumentView in AlertDialog, but I've got extra space between text and right side:
Here is my code:
MainActivity.java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showCommissionDialog();
}
});
}
private void showCommissionDialog() {
MyAlertDialog dialog = new MyAlertDialog();
dialog.show(getSupportFragmentManager(), "dialog");
}
}
MyAlertDialog.java
public class MyAlertDialog extends DialogFragment {
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
View layout = getActivity().getLayoutInflater().inflate(R.layout.dialog, null);
LinearLayout mContent = (LinearLayout) layout.findViewById(R.id.content);
mContent.addView(addTosText());
builder.setView(layout);
return builder.create();
}
private DocumentView addTosText() {
return makeDocumentView(new ArticleBuilder()
.append("d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d " +
"d d d d d d d d d d d d d d d d d d d d d", false)
, DocumentView.FORMATTED_TEXT);
}
public DocumentView makeDocumentView(CharSequence article, int type) {
final DocumentView documentView = new DocumentView(getContext(), type);
documentView.setText(article);
documentView.getDocumentLayoutParams().setTextAlignment(TextAlignment.JUSTIFIED);
return documentView;
}
}
dialog.xml
<LinearLayout
android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" />
How is it possible to avoid this extra space?
I could do this only by using below line of code:
documentView.getDocumentLayoutParams().setInsetPaddingRight(-60);
But this works differently for each form-factor
Could you please help with this issue?