Hello i am making an app where i'm trying to make a cardview with imageview with rounded corner however when i run the app the rounded corners are not showing i dont know what exactly the problem is.
I tried using a custom imageview as well but when i sue that custom imageview imageis getting corner radius but black corners are showing on card and tried checking it on every api level like from android 5-8.
Please check my xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/primary_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="19dp"
android:layout_marginRight="19dp"
android:layout_marginTop="15dp"
app:cardCornerRadius="35dp"
app:contentPadding="0dp"
app:cardPreventCornerOverlap="false"
>
<ImageView
android:id="#+id/background_image_layout"
android:layout_width="match_parent"
android:layout_height="210dp"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="#drawable/club1" />
<LinearLayout
android:id="#+id/background_image"
android:layout_width="match_parent"
android:layout_height="210dp"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/profile_image"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:src="#drawable/ellipse" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<com.ct.listrtrial.Custom.CustomTextViewMedium
android:id="#+id/first_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="18dp"
android:padding="5dp"
android:text="John Doe"
android:textColor="#color/White"
android:textSize="15sp"
/>
<com.ct.listrtrial.Custom.CustomTextViewMedium
android:id="#+id/second_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="18dp"
android:padding="5dp"
android:text="checked in to"
android:textColor="#color/White"
android:textSize="10sp" />
<com.ct.listrtrial.Custom.CustomTextViewMedium
android:id="#+id/third_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="18dp"
android:padding="5dp"
android:text="W south"
android:textColor="#color/White"
android:textSize="15sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:orientation="horizontal">
<com.ct.listrtrial.Custom.CustomTextViewMedium
android:id="#+id/fourth_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="9dp"
android:text="beach mumbai"
android:textColor="#color/White"
android:textSize="15sp" />
<com.ct.listrtrial.Custom.CustomTextViewMedium
android:id="#+id/fifth_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/second_text"
android:layout_toRightOf="#+id/fourth_text"
android:text="30 mins ago."
android:textColor="#color/White"
android:textSize="10sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="85dp">
<com.ct.listrtrial.Custom.CustomTextViewMedium
android:id="#+id/sixth_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"
android:padding="10dp"
android:text="reply to abc............"
android:textColor="#color/White" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerInParent="true">
<ImageView
android:id="#+id/favourite_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="#drawable/ic_favorite_border_black_24dp" />
<com.ct.listrtrial.Custom.CustomTextViewMedium
android:id="#+id/seventh_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:text="40 likes"
android:textColor="#color/White" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
My code for custom imageview
public class RoundedImageView extends ImageView {
private Path mMaskPath;
private Paint mMaskPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
private int mCornerRadius = 10;
public RoundedImageView(Context context) {
super(context);
init(context);
}
public RoundedImageView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
init(context);
}
public RoundedImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context);
}
private void init(Context context) {
ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, null);
mMaskPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
//mMaskPaint.setColor(context.getResources().getColor(R.color.transparent));
mCornerRadius = (int) context.getResources().getDimension(R.dimen.image_border_curvature);
}
/**
* Set the corner radius to use for the RoundedRectangle.
*/
public void setCornerRadius(int cornerRadius) {
mCornerRadius = cornerRadius;
generateMaskPath(getWidth(), getHeight());
invalidate();
}
#Override
protected void onSizeChanged(int w, int h, int oldW, int oldH) {
super.onSizeChanged(w, h, oldW, oldH);
if (w != oldW || h != oldH) {
generateMaskPath(w, h);
}
}
private void generateMaskPath(int w, int h) {
mMaskPath = new Path();
mMaskPath.addRoundRect(new RectF(0,0,w,h), mCornerRadius, mCornerRadius, Path.Direction.CW);
mMaskPath.setFillType(Path.FillType.INVERSE_WINDING);
}
#SuppressLint("WrongConstant")
#Override
protected void onDraw(Canvas canvas) {
if(canvas.isOpaque()) { // If canvas is opaque, make it transparent
canvas.saveLayerAlpha(0, 0, canvas.getWidth(), canvas.getHeight(), 255, Canvas.HAS_ALPHA_LAYER_SAVE_FLAG);
}
super.onDraw(canvas);
if(mMaskPath != null) {
canvas.drawPath(mMaskPath, mMaskPaint);
}
}
}
See this -
layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/reviewLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="19dp"
android:layout_marginRight="19dp"
android:layout_marginTop="15dp"
app:cardCornerRadius="35dp"
app:contentPadding="0dp"
app:cardPreventCornerOverlap="false">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/imgProfile"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_gravity="center"
android:layout_marginRight="100dp"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:src="#drawable/profile" />
</android.support.v7.widget.CardView>
</LinearLayout>
</LinearLayout>
Related
I want to be able to perform onClickListner on root RelativeLayout called "rl". Not it does not work I suspect it can be because of MotionLayout as a children. How to solve that?
Here is what I have done so far, my code.
ShowNoteActivity.java
(...)
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
(...)
RelativeLayout rl = findViewById(R.id.rl);
rl.setOnClickListener(view -> {
Toast.makeText(this, "abc", Toast.LENGTH_SHORT).show();
});
}
show_note_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/rl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true">
<pl.jawegiel.simplenotepad.CustomMotionLayout
android:id="#+id/motion_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="false"
android:focusable="false"
app:layoutDescription="#xml/show_note_activity_scene">
<TextView
android:id="#+id/note_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:clickable="false"
android:duplicateParentState="true"
android:focusable="false"
android:gravity="center"
android:text="#string/note_title"
android:textColor="?attr/myTextColor"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/note_title_value"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/textView3"
android:clickable="false"
android:duplicateParentState="true"
android:focusable="false"
android:gravity="top|left"
android:hint="#string/enter_title"
android:lines="2"
android:maxLines="10"
android:minHeight="48dp"
android:textColor="?attr/myTextColor"
android:textColorHint="?attr/myHintTextColor"
android:textSize="18sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="#id/note_title" />
<TextView
android:id="#+id/note_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/note_title_value"
android:layout_marginTop="10dp"
android:clickable="false"
android:duplicateParentState="true"
android:focusable="false"
android:gravity="center"
android:text="#string/note_desc"
android:textColor="?attr/myTextColor"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/note_title_value" />
<androidx.core.widget.NestedScrollView
android:id="#+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="false"
android:focusable="false"
app:layout_constraintTop_toBottomOf="#id/note_desc">
<RelativeLayout
android:id="#+id/rl2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="false"
android:focusable="false">
<TextView
android:id="#+id/note_desc_value"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="false"
android:focusable="false"
android:textColor="?attr/myTextColor"
android:textColorHint="?attr/myHintTextColor"
android:textSize="18sp" />
</RelativeLayout>
</androidx.core.widget.NestedScrollView>
</pl.jawegiel.simplenotepad.CustomMotionLayout>
</RelativeLayout>
CustomMotionLayout.java
public class CustomMotionLayout extends MotionLayout {
public CustomMotionLayout(Context context) {
super(context);
}
public CustomMotionLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomMotionLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
#Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_MOVE) {
return super.onInterceptTouchEvent(event);
}
return false;
}
}
show_note_activity_scene.xml
<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ConstraintSet android:id="#+id/start">
<Constraint
android:id="#id/note_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<Constraint
android:id="#id/note_title_value"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="#id/note_title"/>
<Constraint
android:id="#id/note_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/note_title_value"/>
</ConstraintSet>
<ConstraintSet android:id="#+id/end">
<Constraint
android:id="#id/note_title"
android:layout_width="match_parent"
android:layout_height="1dp"
android:alpha="0.0"/>
<Constraint
android:id="#id/note_title_value"
android:layout_width="match_parent"
android:layout_height="1dp"
android:alpha="0.0"/>
<Constraint
android:id="#id/note_desc"
android:layout_width="match_parent"
android:layout_height="1dp"
android:alpha="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</ConstraintSet>
<Transition
app:constraintSetEnd="#id/end"
app:constraintSetStart="#id/start"
app:duration="1000">
<OnSwipe
app:touchAnchorSide="top"
app:dragDirection="dragUp"
app:moveWhenScrollAtTop="true"
app:touchAnchorId="#id/nestedScrollView"/>
<KeyFrameSet>
</KeyFrameSet>
</Transition>
</MotionScene>
If you want to click on parent you should disable motionlayout transition and do your transition programmatically with one button or ...
Disable motion layout:
motionLayout.getTransition(R.id.yourTransition).setEnable(false)
If you must to use onSwipe in your project you can disable transition after collapsing motionlayout and return layout to top programmatically and when expand enable motionlayout transition.
I am trying to get the position of items in my RecyclerView, mainly those that are at [0], [1], and [2] positions. The reason being is currently I am creating a leader board that will highlight the top 3 players with the highest score.
I have tried calling getAdapterPosition() but I guess I am using it incorrectly.
if(holder.getAdapterPosition() == 0)
{
Glide.with(holder.firstPlace.getContext())
.load(model.getUrl())
.into(holder.firstPlace);
}
I would greatly appreciate if someone could point me to the right direction. Thank you.
Edit 1:
My UserAdapter
public class UserAdapter extends FirestoreRecyclerAdapter<UserModel, UserAdapter.UserViewHolder> {
public UserAdapter(#NonNull FirestoreRecyclerOptions<UserModel> options) {
super(options);
}
#Override
protected void onBindViewHolder(#NonNull UserAdapter.UserViewHolder holder, int position, #NonNull UserModel model) {
holder.username.setText(model.getFullName());
holder.email.setText(model.getEmail());
holder.score.setText(model.getScore()+"");
holder.rank.setText(String.valueOf(position + 1));
Glide.with(holder.userImage.getContext())
.load(model.getUrl())
.into(holder.userImage);
//error here
// if(holder.getAdapterPosition() == 0)
// {
// Glide.with(holder.firstPlace.getContext())
// .load(model.getUrl())
// .into(holder.firstPlace);
// }
}
#NonNull
#Override
public UserAdapter.UserViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_leaderboard_single, parent, false);
return new UserViewHolder(view);
}
public class UserViewHolder extends RecyclerView.ViewHolder {
CircleImageView userImage;
TextView username;
TextView email;
TextView score;
TextView rank;
CircleImageView firstPlace;
CircleImageView secondPlace;
CircleImageView thirdPlace;
public UserViewHolder(#NonNull View itemView) {
super(itemView);
userImage = itemView.findViewById(R.id.list_image);
username = itemView.findViewById(R.id.list_username);
email = itemView.findViewById(R.id.list_email);
score = itemView.findViewById(R.id.list_score);
rank = itemView.findViewById(R.id.leaderboard_position);
firstPlace = itemView.findViewById(R.id.place1stProfile);
secondPlace = itemView.findViewById(R.id.place2ndProfile);
thirdPlace = itemView.findViewById(R.id.place3rdProfile);
}
}
list_leaderboard_single.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp"
android:orientation="horizontal"
android:background="#EFCDB4">
<RelativeLayout
android:layout_width="32dp"
android:layout_height="match_parent"
android:padding="5dp"
android:background="#FFE5C6"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/leaderboard_position"
android:textStyle="bold"
android:textColor="#000"
android:text="##"
android:layout_centerInParent="true"
android:textSize="18sp"
/>
</RelativeLayout>
<de.hdodenhof.circleimageview.CircleImageView
android:paddingTop="5dp"
android:layout_width="75dp"
android:layout_height="75dp"
android:id="#+id/list_image"
android:src="#mipmap/ic_launcher_round"
android:scaleType="centerCrop"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:layout_toRightOf="#id/leaderboard_position"
/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/list_username"
android:layout_width="173dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:layout_marginTop="26dp"
android:fontFamily="#font/poppinsmedium"
android:layout_toRightOf="#id/list_image"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Username"
android:textColor="#000"
android:textSize="18sp" />
<TextView
android:id="#+id/list_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email"
android:layout_toRightOf="#+id/list_username"
android:layout_centerVertical="true"
android:layout_marginLeft="0dp"
android:textColor="#000"
android:visibility="gone"
/>
</LinearLayout>
<LinearLayout
android:layout_width="80dp"
android:layout_height="80dp"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_marginTop="0dp"
android:id="#+id/list_score"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Score"
android:textSize="25sp"
android:textColor="#000"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PTS"
android:textStyle="bold"
android:fontFamily="#font/poppinsbold"
android:textSize="15sp"
android:textColor="#000"/>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
app:srcCompat="#drawable/ic_blood_drop"
android:visibility="gone"
/>
</LinearLayout>
fragment_leaderboard.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView
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=".Leaderboard"
android:background="#790604">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:layout_marginTop="15dp"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:text="L E A D E R B O A R D"
android:fontFamily="#font/poppinsbold"
android:textColor="#ffffff"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3"
android:layout_marginBottom="16dp"
android:minHeight="150dp">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
>
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/place2ndProfile"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginTop="16dp"
android:scaleType="centerCrop"
android:layout_centerHorizontal="true"
android:src="#mipmap/ic_launcher_round"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textStyle="bold"
android:layout_below="#id/place2ndProfile"
android:fontFamily="#font/poppinsbold"
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp"
android:textColor="#ffffff"
android:text="2ND"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/place1stProfile"
android:layout_width="110dp"
android:layout_height="110dp"
android:layout_marginTop="16dp"
android:scaleType="centerCrop"
android:layout_centerHorizontal="true"
android:src="#mipmap/ic_launcher_round"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="#ffffff"
android:fontFamily="#font/poppinsbold"
android:layout_below="#id/place1stProfile"
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp"
android:text="1ST"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/place3rdProfile"
android:src="#mipmap/ic_launcher_round"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginTop="16dp"
android:scaleType="centerCrop"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="#FFFFFF"
android:fontFamily="#font/poppinsbold"
android:layout_below="#id/place3rdProfile"
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp"
android:text="3RD"/>
</RelativeLayout>
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/leaderboard_list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
You should call holder.getAdapterPosition only within the ViewHolder; instead you can simply use the parameter position passed in onBindViewHolder().
#Override
protected void onBindViewHolder(#NonNull UserAdapter.UserViewHolder holder, int position, #NonNull UserModel model) {
// .....
if(position == 0)
{
Glide.with(holder.firstPlace.getContext())
.load(model.getUrl())
.into(holder.firstPlace);
}
I'm using a view pager on my application with multiple fragment inside, I also disable the my viewpager swipe using these code, but in my layout 'fragment_hr_link.xml' I can swipe it but it got stuck between 2 fragments
viewPager.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
It works fine in some of my fragment but, I'm having problem with this layout, the swipe is working but it got stuck
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.hr.HrLinkFragment">
<ScrollView
android:fillViewport="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:padding="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:rowCount="3"
android:columnCount="2"
android:alignmentMode="alignMargins"
android:columnOrderPreserved="false">
<androidx.cardview.widget.CardView
android:clickable="true"
android:focusable="true"
android:foreground="?android:attr/selectableItemBackground"
android:id="#+id/card_view_hr_daily_schedule"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
app:cardElevation="6dp"
app:cardCornerRadius="8dp"
android:layout_margin="12dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="16dp"
android:orientation="vertical">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="#drawable/ic_launcher_foreground"
android:layout_gravity="center" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Daily Schedule"
android:textSize="16sp"
android:textColor="#3253F8"
android:layout_marginTop="12dp"
android:textAlignment="center" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:clickable="true"
android:focusable="true"
android:foreground="?android:attr/selectableItemBackground"
android:id="#+id/card_view_hr_daily_time_record"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
app:cardElevation="6dp"
app:cardCornerRadius="8dp"
android:layout_margin="12dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="16dp"
android:orientation="vertical">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="#drawable/ic_launcher_foreground"
android:layout_gravity="center" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Daily Time Record"
android:textSize="16sp"
android:textColor="#3253F8"
android:layout_marginTop="12dp"
android:textAlignment="center" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:clickable="true"
android:focusable="true"
android:foreground="?android:attr/selectableItemBackground"
android:id="#+id/card_view_hr_evaluation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
app:cardElevation="6dp"
app:cardCornerRadius="8dp"
android:layout_margin="12dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="16dp"
android:orientation="vertical">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="#drawable/ic_launcher_foreground"
android:layout_gravity="center" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Evalution"
android:textSize="16sp"
android:textColor="#3253F8"
android:layout_marginTop="12dp"
android:textAlignment="center" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:clickable="true"
android:focusable="true"
android:foreground="?android:attr/selectableItemBackground"
android:id="#+id/card_view_hr_leave_balance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
app:cardElevation="6dp"
app:cardCornerRadius="8dp"
android:layout_margin="12dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="16dp"
android:orientation="vertical">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="#drawable/ic_launcher_foreground"
android:layout_gravity="center" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Leave Balance"
android:textSize="16sp"
android:textColor="#3253F8"
android:layout_marginTop="12dp"
android:textAlignment="center" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</GridLayout>
</LinearLayout>
</ScrollView>
You have a viewpager which should not be swipable?
Try making your custom viewpager like this:
public class SwipeDisabledViewPager extends ViewPager {
public SwipeDisabledViewPager(Context context) {
super(context);
}
public SwipeDisabledViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
#Override
public boolean onTouchEvent(MotionEvent ev) {
// returning false will not propagate the swipe event
return false;
}
#Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return false;
}
}
you could also have a look at the new viewPager2 from android architecture components:
https://developer.android.com/reference/androidx/viewpager2/widget/ViewPager2
https://developer.android.com/training/animation/vp2-migration
hope this helps ;-)
Is it possible to use CoordinatorLayout with ListView?
I have tried the following which does not work
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingRight="15dp">
<ru.boloid.giszkh.views.AppTextView
android:id="#+id/title_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:textColor="#android:color/white"
android:textSize="18sp"/>
<TextView
android:id="#+id/address_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:textColor="#android:color/white"
android:textSize="15sp"/>
</LinearLayout>
</android.support.v7.widget.Toolbar>
<LinearLayout
android:id="#+id/no_payment_documents"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/toolbar"
android:background="#EBEFF0"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#null"
android:src="#drawable/attention"/>
<TextView
android:id="#+id/nothing_found_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/payment_documents_nothing_found_text_margin"
android:gravity="center"
android:text="#string/payment_documents_nothing_found"/>
</LinearLayout>
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/toolbar">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:fillViewport="true">
<ListView
android:id="#+id/pay_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/footer"
android:background="#color/list_background"
android:divider="#null"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
</android.support.v4.widget.NestedScrollView>
<!--<ListView-->
<!--android:id="#+id/pay_list"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_above="#+id/footer"-->
<!--android:background="#color/list_background"-->
<!--android:divider="#null"-->
<!--/>-->
<LinearLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/list_background"
app:layout_scrollFlags="scroll|enterAlways"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<LinearLayout
android:id="#+id/amount_to_pay_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/payment_documents_total_accrued"
android:textColor="#color/pay_item_title_text_color"
android:textSize="#dimen/payment_documents_footer_text_size"
android:textStyle="bold"/>
<TextView
android:id="#+id/total_accrued"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/pay_item_title_text_color"
android:textSize="#dimen/payment_documents_footer_text_size"
android:textStyle="bold"
tools:text="995 000.00 P"/>
<ImageView
android:id="#+id/info_amount_in_progress_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:contentDescription="#null"
android:scaleX="#dimen/controls_scale_1.4"
android:scaleY="#dimen/controls_scale_1.4"
android:src="#drawable/info_gray"
android:visibility="invisible"/>
</LinearLayout>
<LinearLayout
android:id="#+id/insurance_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/payment_documents_insurance"
android:textColor="#color/pay_item_title_text_color"
android:textSize="#dimen/payment_documents_footer_text_size"/>
<TextView
android:id="#+id/insurance_amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/pay_item_title_text_color"
android:textSize="#dimen/payment_documents_footer_text_size"
tools:text="132.84 P"/>
<ImageView
android:id="#+id/edit_insurance_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:contentDescription="#null"
android:scaleX="#dimen/controls_scale_1.4"
android:scaleY="#dimen/controls_scale_1.4"
android:src="#drawable/ic_edit"/>
</LinearLayout>
<LinearLayout
android:id="#+id/paid_amount_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/payment_documents_paid"
android:textColor="#color/pay_item_title_text_color"
android:textSize="#dimen/payment_documents_footer_text_size"/>
<TextView
android:id="#+id/paid_amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="36dp"
android:layout_marginRight="36dp"
android:layout_marginTop="8dp"
android:textColor="#color/pay_item_title_text_color"
android:textSize="#dimen/payment_documents_footer_text_size"
tools:text="1 502 000.00 P"/>
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/separator"/>
<ru.boloid.giszkh.views.AppButton
android:id="#+id/pay_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="16dp"
android:drawableLeft="#drawable/ic_card"
android:drawablePadding="10dp"
android:minWidth="130dp"/>
</LinearLayout>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_below="#id/toolbar"
android:background="#drawable/bkgrd_shadow"/>
</RelativeLayout>
Also one more question:
How to make my LinearLayout scroll to the top when I reach the bottom of the ListView?
You can do like this.
1.add CustomListView
public class CustomListView extends ListView {
public CustomListView(Context context) {
super(context);
}
public CustomListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomListView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
#TargetApi(Build.VERSION_CODES.LOLLIPOP)
public CustomListView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
#Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2
, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
}
2.change xml code
You change this.
<ListView
android:id="#+id/lstTask"
android:layout_width="match_parent"
android:layout_height="287dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="12dp"/>
To
<!-- your package name-->
<com.your.app.utils.CustomListView
android:id="#+id/lstTask"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="12dp"/>
You shouldn't need a custom ListView subclass. ListView will work directly with CoordinatorLayout as long as you include this attribute:
android:nestedScrollingEnabled="true"
Then you can use the nested-enabled ListView in exactly the same way you would use a NestedScrollView or RecyclerView.
I am new to Android deve;p[,emt. I apologize for the bad English. I have a question for displaying text in LinearLayout. LinearLayout has a size I set 350x230 dp. There are 10 pieces TextView. When I fill a TextView text, then install them yet, and size, each TextView can have your text size. How can you fit all the TextView in my LinearLayout? If you can - then help with the code. Here is my activity xml:
XML Layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f0e0a2" >
<LinearLayout
android:id="#+id/linearCard"
android:layout_width="350dp"
android:layout_height="230dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:orientation="vertical" >
<com.jaganat.vizicard.CardView
android:id="#+id/card"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="15dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="15dp"
android:background="#fff" >
</com.jaganat.vizicard.CardView>
</LinearLayout>
</RelativeLayout>
JAVA Class:
public class CardView extends LinearLayout {
private View view;
public CardView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public CardView(Context context) {
super(context);
// TODO Auto-generated constructor stub
init(context);
}
private void init(Context context){
LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = layoutInflater.inflate(R.layout.card_view,this);
}
}
my card_view
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearCard"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/tFirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/tFirm2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/tJob"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/tJob2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/tFIO"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/tFIO2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/tOffice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/tOffice2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/tTel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/tMob"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/tFax"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/tTelH"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/tAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/tAddress2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/tEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/tWWW"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>