В настоящее время я пытаюсь создать фрагмент дизайна, который будет отображаться при нажатии кнопки «плюс». Похоже на это.
![enter image description here](https://i.stack.imgur.com/CJbTn.jpg)
Это то, что я получаю.
![enter image description here](https://i.stack.imgur.com/E1oM0.png)
это код для отображения фрагмента.
promptFragment xml:
<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:orientation="vertical">
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="316dp"
android:layout_height="250dp"
android:layout_marginStart="8dp"
android:layout_marginTop="24dp"
android:background="@drawable/promptforadd"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.433"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/textViewTakePhoto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:paddingBottom="180dp"
android:text="Take Photo"
android:textSize="24sp" />
</LinearLayout>
<Button
android:id="@+id/buttonCancel"
android:layout_width="316dp"
android:layout_height="56dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="50dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="@drawable/cancelbutton"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/linearLayout2"
app:layout_constraintVertical_bias="1.0" />
Это текущий дизайн, соответствующий приведенному выше XML-файлу.
![enter image description here](https://i.stack.imgur.com/fYY7s.png)
Это код для раздувания моего фрагмента.
public class PromptFragment extends Fragment {
TextView textViewTakePhoto;
TextView textViewAlbum;
TextView textViewAddOutfit;
Button buttonCancel;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.layout_promptforadd,container,false);
textViewTakePhoto = v.findViewById(R.id.textViewTakePhoto);
//textViewAlbum = v.findViewById(R.id.textViewAlbum);
//textViewAddOutfit = v.findViewById(R.id.textViewAddOutfit);
buttonCancel = v.findViewById(R.id.buttonCancel);
buttonCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(v.getContext(),"you clicked on button ",Toast.LENGTH_SHORT).show();
}
});
return v;
}
}
Я добавил макет фрейма в домашнюю активность, где я хочу, чтобы мой фрагмент раздулся. Я использую фрагмент транзакции, чтобы добавить свой фрагмент в макет кадра. Мой дизайн фрагмента даже не соответствует выводу, который я получаю, поэтому я не уверен, как это сделать.