I'm currently learning the basics of Android programming. I'm able to create a static app with one page and a few buttons. The next step is learn to dynamically create apps, like i'm used to in webapplications.
What i'm trying to do is create a simple facebook-like app with some timeline objects, with some text, a like button and the date it was placed. There is a simple NodeJS server which responds to a http GET request with a JSON file. Which is parsed and for each object in the array there should be a timeline object created, just like there is on facebook.
On my homepage i'm creating some dynamic content to contain the timeline objects.
ConstraintLayout container = activity.findViewById(R.id.container);
container.removeAllViews();
TextView nav_txt = activity.findViewById(R.id.nav_txt);
nav_txt.setText("Home");
swipeRefreshLayout = new SwipeRefreshLayout(activity);
ScrollView scrollView = new ScrollView(activity);
container.addView(swipeRefreshLayout);
scrollView.setLayoutParams(new ConstraintLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ConstraintLayout.LayoutParams.MATCH_PARENT));
linearLayout = new LinearLayout(activity);
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.setId(R.id.linearLayout);
swipeRefreshLayout.addView(scrollView);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
#Override
public void onRefresh() {
refreshData();
}
});
scrollView.addView(linearLayout);
This is easy, the views don't need any constraints, because everything is the same height as the parent.
The timeline objects are more complicated, with a lot of constraints and children with different sizes, so i thought, i create a custom XML file with the timeline object already defined, grab it by the ID and modify it to suit my needs.
My timeline_message.xml looks like this:
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.constraint.ConstraintLayout
android:id="#+id/timeline_msg"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_marginTop="8dp"
android:background="#color/backgroundColor"
app:layout_constraintTop_toTopOf="parent">
<Button
android:id="#+id/like_btn"
android:layout_width="90dp"
android:layout_height="91dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:background="#color/colorPrimary"
android:text="Like"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/username"
android:layout_width="272dp"
android:layout_height="55dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:gravity="center_vertical"
android:text="text"
android:textAlignment="center"
android:textColor="#color/colorPrimary"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/like_btn"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/date"
android:layout_width="91dp"
android:layout_height="40dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:gravity="center_vertical"
android:text="TextView"
android:textAlignment="center"
android:textColor="#color/colorPrimary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.003"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/username"
app:layout_constraintVertical_bias="0.0" />
</android.support.constraint.ConstraintLayout>
And i'm trying to grab the object + children like this:
LinearLayout linearLayout = activity.findViewById(R.id.linearLayout);
ConstraintLayout timelineMsg = activity.findViewById(R.id.timeline_msg);
linearLayout.addView(timelineMsg);
But nothing happens. Is an approach like this possible? Or do you need to write all that code manually with layoutparams and constraints e.t.c.?
You are close you just forgot something
If you want to use your timeline_message.xml layout you need to inflate it before
Example :
LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Then you can use your inflater for inflate a view
View view = inflater.inflate(R.layout.timeline_message, null);
You can now use your view for find your element
ConstraintLayout timelineMsg = view.findViewById(R.id.timeline_msg);
For finish you can add your inflate view to your container with
linearLayout.addView(view);
Related
I have a ConstraintLayout that is a list item inside of a GridView, so there will be multiple of them on the screen. There are various statuses for each item, which are represented by drawables, and each list item has a unique name in a TextView displayed above the drawable.
Basically I have these two inside a Constraint Layout:
<ImageView
android:id="#+id/client_state_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:src="#drawable/client_state_background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/device_client"
style="#style/ClientName"
android:layout_width="64dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="72dp"
android:ellipsize="end"
android:gravity="center"
android:maxLines="1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Where client_state_background can be one of multiple drawables, determined programmatically.
I'm trying to run an espresso test that will ensure that the correct list item is showing the drawable for the status. I tried doing this:
ViewInteraction imageView = onView(allOf(withId(R.id.client_state_image), withParent(withParent(withId(R.id.grid_view))), withDrawable(statusToCheck), isDisplayed()));
imageView.check(matches(isDisplayed()));
With the withDrawable method drawn from here
But I can't find a way to include the TextView in my assertion.
Is there a way to assert that a TextView and ImageView are displaying the correct information, together?
I'm currently testing my code for situations where a RecyclerView.Adapter needs additional information to be displayed in it. Using the code below which is inside onBindViewHolder, I was able to make this work.
TableRow row = new TableRow(mCtx);
row.setLayoutParams(new TableLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
row.setOrientation(LinearLayout.VERTICAL);
TextView lbl = new TextView(mCtx);
lbl.setText("Desc1");
TextView lbl2 = new TextView(mCtx);
lbl2.setText("54.77");
row.addView(lbl);
row.addView(lbl2);
holder.binding.tblTicketItemDetails.addView(row);
That code is always called inside OnBindViewHolder to simulate that each item have additional info in them. If I keep creating an item by pressing a Button, the additional info increases for each item.
How do I target the specific adapter's layout while using DataBinding?
This is the layout that I am using for RecyclerView.Adapter.
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="ticket_item"
type="com.example.com.TicketItem" />
</data>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow
android:id="#+id/tableRow6"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="8dp"
android:weightSum="2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/lblTicketItemName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="8dp"
android:text="#{ticket_item.description}"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold"
tools:text="Test Text" />
<TextView
android:id="#+id/lblTicketItemPrice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end"
android:padding="8dp"
android:text="#{ticket_item.price}"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold"
tools:text="Test Text" />
</TableRow>
<TableLayout
android:id="#+id/tblTicketItemDetails"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tableRow6">
</TableLayout>
</android.support.constraint.ConstraintLayout>
</layout>
I want to add a TableRow with 2 TextViews in tblTicketItemDetails if needed. What is the best way to do this? If I can't do it while using DataBinding, then I would switch to the old way.
I usually add dynamic views like this using Databinding:
#BindingAdapter({"addDynamicView", "position"})
public static void addDynamicView(TableLayout layout, TicketItem item, int position) {
// LayoutInflater inflater = LayoutInflater.from(layout.getContext()); // if you need layout inflater
for (int i = 0; i <= position; i++) { // loop to whatever condition you have
TextView lbl = new TextView(layout.getContext());
lbl.setText("Desc1");
layout.addView(lbl);
}
}
Modify TableLayout in xml,
<TableLayout
android:id="#+id/tblTicketItemDetails"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tableRow6"
app:addDynamicView = "#{ticket_item}"
app:position = "#{position}">
Declare a new variable in xml,
<variable
name="position"
type="int" />
Send position from Java to xml
holder.binding.setVariable(BR.position, position);
or
holder.binding.setPosition(position);
I am very new to android development and android studio; I will try to express my question as clear as possible. If I am using the wrong terminology when referring to some things please let me know along your answer.
What do I want to do?:
I want to create a list of items from an array of strings whose values I have stored in arrays.xml. I want the user to select which of these strings to use by checking a box next to each of them. Additionally I want to add the following after the last item in my array:
[+] _Add_your_own_item__
(The user would write a String and press the [+] button, this will add a new item to the list above with a box to tick as well).
I want this Button + Plain Text to be inside of the ListView that contains the list, as if this Button + text is the last item in the list.
What Have I been able to do so far?:
I have managed to create a dynamic list of checkboxes for all the elements of my array:
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_characters);
listView = (ListView)findViewById(R.id.listView);
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
characters = getResources().getStringArray(R.array.characters);
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, characters);
listView.setAdapter(arrayAdapter);
for(int i = 0; i < characters.length; ++i)
{
listView.setItemChecked(i, false);
}
}
I have tried to create the Button + Plain Text directly modifying the .xml file for my activity, but it just places them outside of the ListViex.
From my very limited understanding my ArrayAdapter turns each string into a "checkbox" view, and places them one below the other in the ListView; how can I do the same for a Button + Text? I only need a push into the right direction, I can then try to figure out the logic to add my new string into the list of checkboxes.
Here is hoy my layout is so far: (That Button in there just tells my which Strings are selected)
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:text="#string/characters"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:onClick="getSelectedSuspects"
android:text="#string/continue_text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<LinearLayout
android:id="#+id/checksContainer"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:orientation="vertical"
app:layout_constraintBottom_toTopOf="#+id/button4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView">
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
The easiest way with ListView is to set a footer view. A footer view is inside the list and scrolls with it, but is not counted as an element of the list. Use listView.addFooterView(view) to add it. The view is typically inflated from xml via a LayoutInflater.
In case someone is in the position I was a couple of hours ago: I will add a more novice friendly response based on what I understood from #Game's answer.
I created a new layout, which would be inserted itself as another ViewGroup at the bottom of my ListView. For the examples in my question that would be:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".DisplayCharactersActivity">
<EditText
android:id="#+id/editText2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Add a suspect"
android:inputType="textPersonName"
android:text=""
app:layout_constraintEnd_toStartOf="#+id/button5"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:text="+"
app:layout_constraintBaseline_toBaselineOf="#+id/editText2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/editText2" />
</android.support.constraint.ConstraintLayout>
And then, in the OnCreate() method of your activity add:
LayoutInflater layoutInflater = getLayoutInflater();
ViewGroup footer = (ViewGroup)layoutInflater.inflate(R.layout.footer_button_text, listView, false);
listView.addFooterView(footer);
I don't understand all the details behind this lines, but it "appends" this ViewGroup at the bottom of the ListView; if anybody wants to explain this in more detail please feel free to edit.
In my code, I'm presenting a custom alert dialog by inflating a layout and set it as the dialog's view.
The problem I'm having is that the text looks OK in the Android Studio's design tool, but at run-time, the dialog becomes smaller and the text takes more lines.
I tried different approaches to fix it, but didn't acquire the wanted result.
For the layout, I'm using constraint layout and the text is "wrap content".
Here's my code:
//inflate alert layout
LayoutInflater inflater = LayoutInflater.from(this);
final View view = inflater.inflate(R.layout.connectivity_issue_counter, null);
//set builder
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setView(view);
dialog.setCancelable(false);
final AlertDialog alert = dialog.create();
//define dialog buttons and counter......//
alert.show();
XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/alertBackground">
<TextView
android:id="#+id/connectivity_issue_title"
style="#style/customAlertTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="50dp"
android:text="#string/connectivity_issue_title"
app:layout_constraintEnd_toStartOf="#+id/connectivity_issue_wait"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/connectivity_issue_wait"
style="#style/customAlertTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:text="#string/connectivity_issue_wait"
app:layout_constraintEnd_toStartOf="#+id/connectivity_issue_counter_text"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/connectivity_issue_counter_text"
style="#style/customAlertTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/connectivity_issue_main_text"
style="#style/customAlertMainText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:text="#string/connectivity_issue_main_text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/connectivity_issue_title" />
<Button
android:id="#+id/connectivity_isuue_button"
style="#style/customAlertButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:text="#string/stop"
app:layout_constraintEnd_toStartOf="#+id/guideline21"
app:layout_constraintStart_toStartOf="#+id/guideline22"
app:layout_constraintTop_toBottomOf="#+id/connectivity_issue_main_text" />
<android.support.constraint.Guideline
android:id="#+id/guideline20"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.82" />
<android.support.constraint.Guideline
android:id="#+id/guideline21"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.75" />
<android.support.constraint.Guideline
android:id="#+id/guideline22"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.25" />
</android.support.constraint.ConstraintLayout>
*Another interesting thing - on a different tablet (both the same model) the dialog looks bigger and wider.
I'll appreciate any help.
As Davidaz suggested, I've changed the text size from sp to dp and it helped to solve the problem.
¿Maybe the text is bigger on that phone? I can't see the customAlertTitle style, but I suppose the text is on "SP", and these are "DP" but text-size dependent (if the phone is set to show the text on a big font from it's settings tab, it will increase it's size).
Maybe a solution could be to set the sizes to "DP", but you won't let the people change it, so it has counter effects.
Another idea that comes to my mind is that the size of the screen you are previewing on the preview is larger than your phone's screen.
The last thing I would try is to change the 'android.R.id.message' TextView's size by hand after creating the dialog. Once you show it you can access the message's textview by calling for it's id,
TextView messageTv = (TextView) alert.findViewById(android.R.id.message);
messageTv.setTextSize(X);
Edit: Don't mind that last idea, as you are inflating your own layout, maybe you can try to access your id and change it the same way, but with R.id.connectivity_issue_wait
I am trying to create a dialog which uses a custom view which also has a number of different behaviours attached, which is why I extended AlertDialog instead of using a builder.
The code that creates the view looks like this looks like this
class MyTaskCreateDialog extends AlertDialog implements DialogInterface.OnCancelListener {
public MyTaskCreateDialog(Context ctx, TaskItem item, List<Person> people, IOnFinishListener listener) {
super(ctx) {
View view = LayoutInflater.from(ctx).inflate(Resource.Layout.dialog_my_task_create, null, false);
setView(view);
setCancelable(true);
setOnCancelListener(this);
setCanceledOnTouchOutside(true);
assign_views(view); //this assigns the views to the local variables
attach_listeners();
refresh_view();//this updates the view with data
}
the above uses this layout file
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="#dimen/app_padding">
<android.support.design.widget.TextInputLayout
android:id="#+id/my_task_create_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/app_margin"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/my_task_create_hint_title" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/my_task_create_description"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="#+id/my_task_create_title"
app:layout_constraintStart_toStartOf="#+id/my_task_create_title"
app:layout_constraintTop_toBottomOf="#+id/my_task_create_title">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/my_task_create_hint_description" />
</android.support.design.widget.TextInputLayout>
<TextView
android:id="#+id/my_task_create_assignee_caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/my_task_create_caption_assignee"
app:layout_constraintBottom_toBottomOf="#+id/my_task_create_assignee"
app:layout_constraintStart_toStartOf="#+id/my_task_create_description"
app:layout_constraintTop_toTopOf="#+id/my_task_create_assignee" />
<Spinner
android:id="#+id/my_task_create_assignee"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/app_margin"
android:checked="true"
android:padding="#dimen/app_padding"
android:textOff="#string/my_task_create_toggle_manually"
android:textOn="#string/my_task_create_toggle_automatically"
app:layout_constraintEnd_toEndOf="#+id/my_task_create_description"
app:layout_constraintStart_toEndOf="#+id/my_task_create_assignee_caption"
app:layout_constraintTop_toBottomOf="#+id/my_task_create_description"
tools:listitem="#android:layout/simple_spinner_item" />
<Button
android:id="#+id/my_task_create_create_task"
style="#style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/app_margin"
android:text="#string/my_task_create_button_create"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/my_task_create_cancel"
app:layout_constraintTop_toBottomOf="#+id/my_task_create_assignee" />
<Button
android:id="#+id/my_task_create_cancel"
style="#style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/app_margin"
android:text="#string/my_task_create_button_cancel"
app:layout_constraintEnd_toStartOf="#+id/my_task_create_create_task"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/my_task_create_assignee" />
</android.support.constraint.ConstraintLayout>
which creates a dialog with big padding at the bottom.
in fact is I change the background of the ConstraintLayout to be greyish, then the bottom half of the dialog seems to be the default color.
the result of the above looks like this:
now I know that some space is saved for the buttons (I do not use those, I use custom ones from the layout file), but how can I make the rest of the space disappear and make my dialog wrap its content?
I was having the same problem, and the only solution that worked for me is to add the following code into all Views inside of ConstraintLayout:
android:layout_height="0dp"
app:layout_constraintHeight_default="wrap"
Those sentences replace this:
android:layout_height="wrap_content"