0

I am creating a dialogue with a number picker and a button but unfortunately it is taking up the entire screen.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<NumberPicker
    android:id="@+id/numberPicker1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:descendantFocusability="blocksDescendants"

    android:layout_marginTop="64dp" />


<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/numberPicker1"
    android:text="Set" />

</RelativeLayout> 

Here is how i am creating the dialogue

        final Dialog d = new Dialog(CreateShiftActivity.this, R.style.Theme_AppCompat);
    d.setTitle("NumberPicker");
    d.setContentView(R.layout.num_dialog);
Shubham Gajra
  • 37
  • 1
  • 5

2 Answers2

0

Try to wrap your relative layout:

android:layout_width="wrap_content"
android:layout_height="wrap_content"

I suggest so use Constraint layout in future.

Hope it helps.

Edit

try this whit Constraints:

<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="wrap_content"
        android:layout_height="wrap_content">

    <NumberPicker
            android:id="@+id/numberPicker1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent" android:layout_marginTop="8dp"/>


    <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Set" android:layout_marginTop="8dp" app:layout_constraintTop_toBottomOf="@+id/numberPicker1"
            app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintBottom_toBottomOf="parent" android:layout_marginBottom="8dp"
            android:layout_marginStart="8dp" android:layout_marginEnd="8dp"/>

</android.support.constraint.ConstraintLayout>
Andrea Ebano
  • 523
  • 1
  • 4
  • 15
0

Try using AlertDialog instead

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(CreateShiftActivity.this, R.style.Theme_AppCompat);
LayoutInflater inflater = getLayoutInflater();
View convertView = inflater.inflate(R.layout.num_dialog, null);
alertDialogBuilder.setView(convertView);
alertDialogBuilder.setTitle("NumberPicker");
alertDialogBuilder.show();
jampez77
  • 4,071
  • 7
  • 26
  • 48