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.
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'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 ;-)
I want to achieve something not usual for a AppBarLayout + Recyclerview scrollingviewbehavior effect.
I want to make the recyclerview move with AppBarLayout and go behind AppBarLayout when user scrolls. I need it to be really behind AppBarlayout because the background of AppbarLayout will be half transparent so recyclerview will be visible.
I don't know how to do this.
I did try multiple variants of ScrollViewBehavior.
I did try also setting negative values to SwipeRefreshlayout topMaring and change this value during scroll. Values where provided from AppBarLayout.addOnOffsetChangedListener from given i "vertical scroll offset". The result was that the swipeRefreshLayout flickered during scroll and during going behind AppBarLayout.
Please help me with this. I have no more options left.
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="#+id/clRootMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="false"
android:background="#color/backgroundGray">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="#+id/srlSwipeRefresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"
android:isScrollContainer="true"
app:layout_behavior=".Util.View.ScrollingViewOverlapBehavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rvList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:divider="#android:color/transparent"
android:dividerHeight="#dimen/dp5"
android:drawSelectorOnTop="true"
android:fadeScrollbars="true"
android:fadingEdge="none"
android:fadingEdgeLength="#dimen/dp0"
android:gravity="center"
android:isScrollContainer="true"
android:nestedScrollingEnabled="true"
android:overScrollMode="never"
android:paddingLeft="#dimen/list_margin"
android:paddingRight="#dimen/list_margin"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbarSize="#dimen/dp4"
android:scrollbarStyle="outsideOverlay"
android:scrollbars="vertical"
android:smoothScrollbar="false"
app:fastScrollEnabled="true"
app:fastScrollHorizontalThumbDrawable="#drawable/scrollbar_draggable"
app:fastScrollHorizontalTrackDrawable="#drawable/scrollbar_track_line"
app:fastScrollVerticalThumbDrawable="#drawable/scrollbar_draggable"
app:fastScrollVerticalTrackDrawable="#drawable/scrollbar_track_line" />
<TextView
android:id="#+id/tvEmptyListText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="#dimen/dp20"
android:layout_marginTop="#dimen/dp10"
android:layout_marginRight="#dimen/dp20"
android:alpha="0.5"
android:gravity="center"
android:text="#string/category_product_list_empty"
android:textColor="#color/textGreyDark"
android:visibility="gone" />
</LinearLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/ablMain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#80ffffff"
android:fitsSystemWindows="true"
android:orientation="vertical"
app:liftOnScroll="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:orientation="vertical"
app:layout_scrollFlags="scroll|enterAlwaysCollapsed|exitUntilCollapsed">
<LinearLayout
android:id="#+id/llOpenOrderListContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
<TextView
android:id="#+id/tvOpenOrdersTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/dp10"
android:layout_marginTop="#dimen/dp15"
android:alpha="0.6"
android:clickable="false"
android:gravity="center|left"
android:singleLine="true"
android:text="#string/current_orders_title"
android:textAllCaps="true"
android:textAppearance="#style/TextAppearance.AppCompat.Body2"
android:textColor="#color/textColor"
android:textSize="#dimen/sp10"
android:textStyle="normal" />
<androidx.viewpager.widget.ViewPager
android:id="#+id/vpOpenOrderList"
android:layout_width="match_parent"
android:layout_height="#dimen/dp75"
android:background="#android:color/transparent"
android:visibility="visible" />
</LinearLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="#+id/rlTopContainer"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#android:color/white"
app:layout_constraintDimensionRatio="H,16:9"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.viewpager.widget.ViewPager
android:id="#+id/vpBannerPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent" />
<RelativeLayout
android:id="#+id/rlControlContainer"
android:layout_width="#dimen/dp100"
android:layout_height="#dimen/dp30"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="#dimen/dp15"
android:background="#android:color/transparent">
<com.google.android.material.tabs.TabLayout
android:id="#+id/tlBannerDots"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
app:tabBackground="#drawable/tab_selector_images"
app:tabGravity="center"
app:tabIndicatorHeight="0dp"
app:tabMinWidth="#dimen/dp3"
app:tabMode="fixed" />
</RelativeLayout>
<ImageView
android:id="#+id/ivHalfCircleBackgroundWithStroke"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_marginTop="#dimen/dp50"
android:scaleType="fitXY"
app:srcCompat="#drawable/ic_bottom_arc"
/>
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
<RelativeLayout
android:id="#+id/rlCategoryContainer"
android:layout_width="match_parent"
android:layout_height="#dimen/dp75"
android:background="#android:color/transparent">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rvCategoryList"
android:layout_width="wrap_content"
android:layout_height="#dimen/dp70"
android:layout_above="#+id/llSeparatorLine"
android:layout_centerHorizontal="true"
android:clipChildren="false"
android:divider="#android:color/white"
android:dividerHeight="#dimen/dp10"
android:drawSelectorOnTop="true"
android:fadeScrollbars="true"
android:fastScrollEnabled="false"
android:gravity="center"
android:isScrollContainer="true"
android:nestedScrollingEnabled="true"
android:overScrollMode="never"
android:scrollIndicators="none"
android:scrollbars="none" />
<LinearLayout
android:id="#+id/llSeparatorLine"
android:layout_width="match_parent"
android:layout_height="#dimen/dp1"
android:layout_alignParentBottom="true"
android:background="#drawable/grey_line_with_fading_edges_light"
android:orientation="horizontal" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rlBottomDownArcContainer"
android:layout_width="match_parent"
android:layout_height="#dimen/dp40"
android:background="#android:color/transparent">
<TextView
android:id="#+id/tvSectionName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#android:color/transparent"
android:clickable="false"
android:gravity="center_horizontal|top"
android:singleLine="true"
android:text="KWIATY"
android:textAllCaps="true"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textColor="#color/textGrey"
android:textSize="#dimen/sp12"
android:textStyle="bold" />
</RelativeLayout>
</com.google.android.material.appbar.AppBarLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fabFilter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginLeft="#dimen/dp5"
android:layout_marginTop="#dimen/dp5"
android:layout_marginRight="#dimen/dp10"
android:layout_marginBottom="#dimen/dp10"
android:elevation="#dimen/dp4"
android:stateListAnimator="#animator/lift_on_touch"
android:visibility="visible"
app:backgroundTint="#android:color/white"
app:borderWidth="0dp"
app:elevation="4dp"
app:fabSize="normal"
app:rippleColor="#color/colorAccent"
app:srcCompat="#drawable/ic_icon_filtr_black" />
<!--</RelativeLayout>-->
</androidx.coordinatorlayout.widget.CoordinatorLayout>
public class ScrollingViewOverlapBehavior extends AppBarLayout.ScrollingViewBehavior {
public ScrollingViewOverlapBehavior() {
super();
}
public ScrollingViewOverlapBehavior(Context context, AttributeSet attrs) {
super(context, attrs);
}
#Override
public boolean onDependentViewChanged(CoordinatorLayout parent, View child,
View dependency) {
super.onDependentViewChanged(parent, child, dependency);
child.setTranslationY(dependency.getY());
return false;
}
}
This is what I have achieved so far but it leaves space at the bottom. I am using setTranslationY on my custom ScrollingViewBehavior (ScrollingViewOverlapBehavior).
https://drive.google.com/open?id=12Ri87BGKmAmwNq_rC-wpmCcYZyansmGl
I have created a Custom Adapter to show ImageView and TextView together in ListView. But the ImageView is showing on the top of TextView in every row of Listview. I have attached a screenshot of app below:
Custom Adapter Class:
public class CustomeAdapter extends BaseAdapter {
private Context context;
private ListView listView;
private ArrayList<PlayersModel> playersModelArrayList;
public CustomeAdapter(Context context, ArrayList<PlayersModel> playersModelArrayList) {
this.context = context;
this.playersModelArrayList = playersModelArrayList;
}
#Override
public int getViewTypeCount() {
return getCount();
}
#Override
public int getItemViewType(int position) {
return position;
}
#Override
public int getCount() {
return playersModelArrayList.size();
}
#Override
public Object getItem(int position) {
return playersModelArrayList.get(position);
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(int position,View convertView,ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.lv_item, null, true);
holder.icon = (TextView) convertView.findViewById(R.id.TextID);
holder.tvname = (TextView) convertView.findViewById(R.id.name);
holder.tvdescr = (TextView) convertView.findViewById(R.id.descr);
holder.tvlink = (TextView) convertView.findViewById(R.id.link);
holder.ImageIcon = (ImageView) convertView.findViewById(R.id.logoImageView);
convertView.setTag(holder);
}else {
holder = (ViewHolder)convertView.getTag();
}
holder.ImageIcon.setImageResource(playersModelArrayList.get(position).getImageId());
holder.icon.setText(playersModelArrayList.get(position).getICON());
holder.tvname.setText(playersModelArrayList.get(position).getName());
holder.tvdescr.setText(playersModelArrayList.get(position).getDescr());
holder.tvlink.setText(playersModelArrayList.get(position).getLink());
Glide.with(context)
.load("http://csalabs.in/wp-content/uploads/2017/10/CSA-Final-PNG-300x350.png")
.override(200,200)
.into(holder.ImageIcon);
Log.d("Icon URL",holder.icon.toString());
return convertView;
}
private class ViewHolder {
protected TextView icon, tvname, tvdescr, tvlink;
protected ImageView ImageIcon;
}
}
Layout File
<?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:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:onClick="buttonClickNew">
<ImageView
android:id="#+id/logoImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitStart"
android:adjustViewBounds="true"
tools:srcCompat="#tools:sample/avatars[0]" />
<TextView
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#383838"
android:layout_marginTop="10dp"
android:textSize="15sp"
android:textStyle="bold"
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceMedium"
android:paddingLeft="10dp"
android:text="Name" />
<TextView
android:id="#+id/descr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#313131"
android:textSize="12sp"
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceMedium"
android:paddingLeft="10dp"
android:text="Country" />
<TextView
android:id="#+id/link"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#383838"
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceMedium"
android:paddingLeft="10dp"
android:text="#string/city"
android:visibility="gone"/>
<TextView
android:id="#+id/TextID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#313131"
android:textSize="12sp"
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceMedium"
android:paddingLeft="10dp"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#color/colorAccent"/>
</LinearLayout>
How to align ImageView on the left side of TextView? Thanks in advance.
BTW I am newbie in android and java.
Try this
<?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:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/logoImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitStart"
tools:srcCompat="#tools:sample/avatars[0]" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="buttonClickNew"
android:orientation="vertical">
<TextView
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="Name"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#383838"
android:textSize="15sp"
android:textStyle="bold" />
<TextView
android:id="#+id/descr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="Country"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#313131"
android:textSize="12sp" />
<TextView
android:id="#+id/link"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="city"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#383838"
android:visibility="visible" />
<TextView
android:id="#+id/TextID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#313131"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:background="#color/colorAccent" />
</LinearLayout>
Use like this:
<?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:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:onClick="buttonClickNew">
<ImageView
android:id="#+id/logoImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitStart"
android:adjustViewBounds="true"
tools:srcCompat="#tools:sample/avatars[0]" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:onClick="buttonClickNew">
<TextView
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#383838"
android:layout_marginTop="10dp"
android:textSize="15sp"
android:textStyle="bold"
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceMedium"
android:paddingLeft="10dp"
android:text="Name" />
<TextView
android:id="#+id/descr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#313131"
android:textSize="12sp"
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceMedium"
android:paddingLeft="10dp"
android:text="Country" />
<TextView
android:id="#+id/link"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#383838"
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceMedium"
android:paddingLeft="10dp"
android:text="#string/city"
android:visibility="gone"/>
<TextView
android:id="#+id/TextID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#313131"
android:textSize="12sp"
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceMedium"
android:paddingLeft="10dp"/>`enter code here`
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#color/colorAccent"/>
</LinearLayout>
Try to wrap Your text to separated LinearLayout with vertical orientation, and than put this LinearLayout with text on same level as ImageView inside another LinearLayout with orientation="horizontal"
But also, you should remember about render and measure performance.
You can read about this in https://android.jlelse.eu/constraint-layout-performance-870e5f238100
<LinearLayout
android:orientation="horizontal">
<ImageView
android:layout_width="0dp"
android:layout_weight="1" // try to read about this parameter more
/>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="4"
android:orientation="vertical">
<TextView ... />
<TextView ... />
<TextView ... />
</LinearLayout>
</LinearLayout>
Try to create two linear layouts with orientation vertical under parent linear layout which has the horizontal orientation.
Set the second linear layout's width to match_parent and the image layout should be a fixed width value.
<?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:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="buttonClickNew"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<ImageView
android:id="#+id/logoImageView"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
tools:srcCompat="#tools:sample/avatars[0]" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="Name"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#383838"
android:textSize="15sp"
android:textStyle="bold" />
<TextView
android:id="#+id/descr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="Country"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#313131"
android:textSize="12sp" />
<TextView
android:id="#+id/link"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="City"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#383838"
android:visibility="gone" />
<TextView
android:id="#+id/TextID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#313131"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:background="#color/colorAccent" />
</LinearLayout>
In order to simplify your xml, you should take a look to ConstraintLayout
To use it, make the import in your app gradle by adding implementation 'com.android.support.constraint:constraint-layout:1.1.3'
Then, refactor your xml as below:
<?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">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/colorAccent" android:id="#+id/view"
tools:layout_editor_absoluteX="0dp" app:layout_constraintTop_toBottomOf="#+id/logoImageView"
android:layout_marginTop="8dp"/>
<ImageView
android:layout_width="64dp"
android:layout_height="64dp" tools:srcCompat="#tools:sample/avatars"
android:id="#+id/logoImageView"
app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="8dp"
android:layout_marginTop="8dp" app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:id="#+id/name"
tools:text="Name"
android:textAppearance="#style/TextAppearance.AppCompat" android:textStyle="bold"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toTopOf="#+id/descr" app:layout_constraintStart_toEndOf="#+id/logoImageView"
android:layout_marginStart="8dp"/>
<TextView
tools:text="Description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/descr" android:textColor="#313131"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="#+id/logoImageView"
app:layout_constraintStart_toEndOf="#+id/logoImageView" android:layout_marginStart="8dp"/>
</android.support.constraint.ConstraintLayout>
I have a ListView and it has a Header and Footer. Their layout in CardView. And Content list in which one must be background. Here is a picture which can be clearly seen: I now this is how it turns out:
And how to do:
I did so, ScrollView> first container>listView in second container > third container. But, unfortunately, at the bottom of the container 2 it was a huge empty space!
Is it possible to implement a so-in ListView? if so how, if not then how to implement?
UPDATE
<?xml version="1.0" encoding="utf-8"?>
<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"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".Details.Book.BookDetails"
android:background="#color/fragment_bg">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"/>
<View android:layout_width="match_parent"
android:layout_height="3dp"
android:background="#drawable/toolbar_shadow"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/toolbar"
android:id="#+id/view5" />
<ScrollView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/scrollView6"
android:layout_below="#+id/toolbar">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/toolbar">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="#+id/toolbar"
android:id="#+id/linearLayout16">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="#drawable/rounded_top_layout"
android:paddingBottom="#dimen/leftPadding"
android:paddingLeft="#dimen/rightPadding"
android:paddingRight="#dimen/rightPadding"
android:paddingTop="#dimen/leftPadding">
<TextView
android:id="#+id/textviewTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="false"
android:layout_centerVertical="true"
android:text="#string/buy_det_pass_txt"
android:textColor="#color/background_color"
android:textSize="#dimen/mainLargeSize" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/relativeLayout9"
android:paddingBottom="#dimen/leftPadding"
android:paddingLeft="#dimen/rightPadding"
android:paddingRight="#dimen/rightPadding"
android:paddingTop="#dimen/leftPadding">
<LinearLayout
android:id="#+id/linearLayout4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/relativeLayout9"
android:layout_marginBottom="#dimen/textMargin"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/buy_det_fullname"
android:textColor="#color/mainGreyColor"
android:textSize="#dimen/mainSmallSize" />
<TextView
android:id="#+id/tvFullName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="Medium Text"
android:textColor="#color/mainGreyColor"
android:textSize="#dimen/mainMiddleSize" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/linearLayout4"
android:layout_marginBottom="#dimen/textMargin"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/buy_det_gender"
android:textColor="#color/mainGreyColor"
android:textSize="#dimen/mainSmallSize" />
<TextView
android:id="#+id/tvGender"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="Medium Text"
android:textColor="#color/mainGreyColor"
android:textSize="#dimen/mainMiddleSize" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/linearLayout3"
android:layout_marginBottom="#dimen/textMargin"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/buy_det_ticknumber"
android:textColor="#color/mainGreyColor"
android:textSize="#dimen/mainSmallSize" />
<TextView
android:id="#+id/tvTickNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="Medium Text"
android:textColor="#color/mainGreyColor"
android:textSize="#dimen/mainMiddleSize" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/linearLayout6"
android:layout_marginBottom="#dimen/textMargin"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/buy_det_issdate"
android:textColor="#color/mainGreyColor"
android:textSize="#dimen/mainSmallSize" />
<TextView
android:id="#+id/tvIssDate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="Medium Text"
android:textColor="#color/mainGreyColor"
android:textSize="#dimen/mainMiddleSize" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
<kz.tem_tour.Primer.MainActivity.NonScrollListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/listView"
android:layout_centerHorizontal="true"
android:paddingRight="#dimen/textMargin"
android:paddingLeft="#dimen/textMargin"
android:layout_below="#+id/linearLayout16" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="#+id/listView">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="#drawable/rounded_top_layout"
android:paddingTop="#dimen/leftPadding"
android:paddingBottom="#dimen/leftPadding"
android:paddingLeft="#dimen/rightPadding"
android:paddingRight="#dimen/rightPadding">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/buy_det_cost_txt"
android:id="#+id/tvFromTo"
android:textColor="#color/background_color"
android:textSize="#dimen/mainLargeSize"
android:layout_alignParentTop="false"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/relativeLayout9"
android:paddingRight="#dimen/rightPadding"
android:paddingLeft="#dimen/rightPadding"
android:paddingTop="#dimen/leftPadding"
android:paddingBottom="#dimen/leftPadding">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/relativeLayout9"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/linearLayout4"
android:gravity="center_vertical"
android:layout_marginBottom="#dimen/textMargin" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/buy_det_fare"
android:layout_weight="1"
android:textColor="#color/mainGreyColor"
android:textSize="#dimen/mainSmallSize" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Medium Text"
android:id="#+id/tvFare"
android:layout_weight="1"
android:textColor="#color/mainGreyColor"
android:gravity="right"
android:textSize="#dimen/mainMiddleSize" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayout4"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/linearLayout3"
android:gravity="center_vertical"
android:layout_marginBottom="#dimen/textMargin">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/buy_det_taxes"
android:layout_weight="1"
android:textColor="#color/mainGreyColor"
android:textSize="#dimen/mainSmallSize" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Medium Text"
android:id="#+id/tvTaxes"
android:layout_weight="1"
android:textColor="#color/mainGreyColor"
android:gravity="right"
android:textSize="#dimen/mainMiddleSize" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayout3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/linearLayout6"
android:gravity="center_vertical"
android:layout_marginBottom="#dimen/textMargin">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/buy_det_service_fees"
android:layout_weight="1"
android:textColor="#color/mainGreyColor"
android:textSize="#dimen/mainSmallSize" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Medium Text"
android:id="#+id/tvFees"
android:layout_weight="1"
android:textColor="#color/mainGreyColor"
android:gravity="right"
android:textSize="#dimen/mainMiddleSize" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayout6"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/linearLayout7"
android:gravity="center_vertical"
android:layout_marginBottom="#dimen/textMargin">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/buy_det_total_price"
android:layout_weight="1"
android:textColor="#color/mainGreyColor"
android:textSize="#dimen/mainSmallSize" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Medium Text"
android:id="#+id/tvTotPrice"
android:layout_weight="1"
android:textColor="#color/mainGreyColor"
android:gravity="right"
android:textSize="#dimen/mainMiddleSize" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayout7"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/linearLayout15"
android:gravity="center_vertical"
android:layout_marginBottom="#dimen/textMargin" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/buy_det_form_of_pay"
android:layout_weight="1"
android:textColor="#color/mainGreyColor"
android:textSize="#dimen/mainSmallSize" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Medium Text"
android:id="#+id/tvPayment"
android:layout_weight="1"
android:textColor="#color/mainGreyColor"
android:gravity="right"
android:textSize="#dimen/mainMiddleSize" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
I have solution for that.. not healthy one but it should work for you.
Rather then adding header and footer wrap all three layout inside ScrollView.
<ScrollView ... >
<CardView ... /> <!-- this will be header -->
<CardView ...>
<yourpackagename.NonScrollListView ... /> <!-- non scrollable listview -->
</CardView>
<CardView ... /> <!-- this will footer -->
</ScrollView>
Here is the class for NonScrollListView
public class NonScrollListView extends ListView {
public NonScrollListView(Context context) {
super(context);
}
public NonScrollListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public NonScrollListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
#Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int heightMeasureSpec_custom = MeasureSpec.makeMeasureSpec(
Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, heightMeasureSpec_custom);
ViewGroup.LayoutParams params = getLayoutParams();
params.height = getMeasuredHeight();
}
}
Add listview in CardView and above that cardview add header in different card view and same add footer in cardview under ListView cardview. And add whole layout is scrollview. Calculate height of listview at runtime and add height to listview. Your custom look is ready.
public static void setTotalHeightofListView(ListView listView) {
ListAdapter mAdapter = listView.getAdapter();
int totalHeight = 0;
for (int i = 0; i < mAdapter.getCount(); i++) {
View mView = mAdapter.getView(i, null, listView);
mView.measure(
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
totalHeight += mView.getMeasuredHeight();
Log.w("HEIGHT" + i, String.valueOf(totalHeight));
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight
+ (listView.getDividerHeight() * (mAdapter.getCount() - 1));
listView.setLayoutParams(params);
listView.requestLayout();
}