Я пытаюсь сделать выдвижной ящик как пользовательский вид, но приложение cra sh и говорит мне, что атрибут ручки выдвижного ящика требует.
это мой код:
пользовательский выдвижной ящик :
public class Drawerlayout extends SlidingDrawer {
@Override
public View getHandle() {
return binding.handler;
}
private DrawerViewLayoutBinding binding;
private DrawerViewModel viewModel;
private Context context;
public Drawerlayout(Context context, AttributeSet attrs) {
super(context, attrs);
binding = DataBindingUtil.inflate(LayoutInflater.from(context) , R.layout.drawer_view_layout,this,false);
this.context = context;
setupDrawerMenu();
}
private void setupDrawerMenu() {
viewModel = new DrawerViewModel();
// get drawer items from man view model
DrawerDataModel[] drawerDataModel = viewModel.setupDrawerMenu();
// setting adapter
CustomDrawerAdapter customDrawerAdapter =
new CustomDrawerAdapter(context, R.layout.drawer_items, drawerDataModel, viewModel);
// drawerLayout = mainBinding.drawerLayout;
ListView drawerList = binding.rightDrawer;
drawerList.setAdapter(customDrawerAdapter);
}
private void goToTargetActivity(int position) {
switch (position) {
case 0:
context.startActivity(new Intent(context, ProfileActivity.class));
break;
case 1:
context.startActivity(new Intent(context, LibraryActivity.class));
break;
case 2:
context.startActivity(new Intent(context, BankLinkActivity.class));
break;
case 3:
context.startActivity(new Intent(context, SettingsActivity.class));
break;
case 4:
// close application
System.exit(1);
break;
}
}
public void setLifeCycleOwner(LifecycleOwner lifeCycleOwner)
{
if(viewModel == null)
return;
viewModel.drawerItemClicked.observe(lifeCycleOwner , integer -> {
if (integer != -1) {
goToTargetActivity(integer);
}
});
}
}
это раздутый макет в моем пользовательском классе:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="appVersion"
type="String" />
<variable
name="activityOwner"
type="android.app.Activity" />
</data>
<SlidingDrawer
android:id="@+id/drawer"
android:layout_width="300dp"
android:layout_height="match_parent"
android:handle="@+id/handler"
android:content="@+id/drawer_content_container"
android:orientation="horizontal">
<ImageView
android:id="@id/handler"
android:layout_width="wrap_content"
android:layout_height="64dp"
android:layout_marginTop="@dimen/margin_xxxxLarge"
android:adjustViewBounds="true"
android:elevation="@dimen/card_elevation_high"
android:scaleType="centerCrop"
android:src="@drawable/slide_left"
/>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@id/drawer_content_container"
android:layout_width="270dp"
android:layout_height="match_parent"
android:layout_gravity="right"
android:background="@color/white">
<ImageView
android:id="@+id/header_image"
android:layout_width="match_parent"
android:layout_height="120dp"
android:src="@color/green_main"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/profile_image"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_alignTop="@id/header_image"
android:layout_alignBottom="@id/header_image"
android:layout_marginRight="@dimen/margin_normal"
android:src="@drawable/default_pro_image"
app:civ_border_color="#fff"
app:civ_border_width="1dp"
app:layout_constraintBottom_toBottomOf="@id/header_image"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@id/header_image" />
<ListView
android:id="@+id/right_drawer"
android:layout_width="270dp"
android:layout_height="0dp"
android:layout_gravity="right"
android:layout_marginBottom="@dimen/margin_normal"
android:background="#FFFFFF"
android:divider="@null"
app:layout_constraintBottom_toTopOf="@id/logo_image"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/header_image" />
<com.textco.system.salehin.customview.MyTextView
android:id="@+id/name_text"
style="@style/title_text_wh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/margin_normal"
android:gravity="center_vertical"
android:text="علی محمدی"
app:layout_constraintBottom_toBottomOf="@id/header_image"
app:layout_constraintRight_toLeftOf="@id/profile_image"
app:layout_constraintTop_toTopOf="@id/header_image" />
<com.textco.system.salehin.customview.MyTextView
android:id="@+id/mobile_text"
style="@style/desc_text_wh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_xxsmall"
android:layout_marginRight="@dimen/margin_normal"
android:gravity="center"
android:text="09121235212"
app:layout_constraintRight_toLeftOf="@id/profile_image"
app:layout_constraintTop_toBottomOf="@id/name_text" />
<ImageView
android:id="@+id/logo_image"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="@dimen/margin_normal"
android:layout_marginBottom="@dimen/margin_normal"
android:src="@drawable/salehin_logo"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
/>
<com.textco.system.salehin.customview.MyTextView
android:id="@+id/version_text"
style="@style/title_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/margin_normal"
android:text="@{String.format(`نسخه: `) + String.format(appVersion)}"
app:layout_constraintBottom_toBottomOf="@id/logo_image"
app:layout_constraintRight_toLeftOf="@+id/logo_image"
app:layout_constraintTop_toTopOf="@id/logo_image"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</SlidingDrawer>
И использовать его в моей основной деятельности:
.
.
.
<com.textco.system.salehin.drawermenu.Drawerlayout
android:id="@+id/drawer"
android:layout_width="300dp"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
.
.
.
Я знаю, что я должен установить android:handle=""
и android:content="
в моей основной раскладке активности, тогда я должен добавить ImageView
и ViewGroup
как дочерний элемент, скользящий по раскладке основной активности, и сделать мой код грязным ... любая помощь реализовать выдвижной ящик как пользовательский вид ???