I have 3 HorizontalScrollview, for each of them i have customView contain editText that i add dynamically depend from web service response. The problem is, when i want to change value in editText and keyboard appear, the HorizontalScrollView scroll automatically to the end, so i can't properly input value to my edit text. My Question is how to prevent autoscroll in my HorizontalScrollView so i can input value on my editText? and the HorizontalScrollView only scroll when user scroll it.
I've search and my problem similar with this thread but the sugestion didn't work. here is workaround that i already try :
Add android:windowSoftInputMode="stateHidden|adjustNothing" or
android:windowSoftInputMode="stateHidden|adjustResize" already try
adjustPan and other combination but it's impact nothing.
Add android:descendantFocusability="beforeDescendants"
android:focusable="true"
android:focusableInTouchMode="true" in LinearLayout inside my HorizontalScrollView and it's also impact Nothing.
Add android:descendantFocusability="blocksDescendants the
HorizontalScrollView didn't scroll automatically but i can't change value on my edit text, it similar when i add android:focusable = "false" in my editText
Add code bellow but impact nothing.
scrollLayout.descendantFocusability = ViewGroup.FOCUS_BEFORE_DESCENDANTS
scrollLayout.isFocusable = true
scrollLayout.isFocusableInTouchMode = true
scrollLayout.setOnTouchListener { v, event ->
v.requestFocusFromTouch()
false}
Here is My Code
private fun setUpList(rootLayout: LinearLayout, scrollLayout: HorizontalScrollView, items: List<ProductItem>) {
//config horizontal scroll view
scrollLayout.descendantFocusability = ViewGroup.FOCUS_BEFORE_DESCENDANTS
scrollLayout.isFocusable = true
scrollLayout.isFocusableInTouchMode = true
scrollLayout.setOnTouchListener { v, event ->
v.requestFocusFromTouch()
false
}
// add customView to linear layout
rootLayout.removeAllViews()
for (item in items) {
val view = EditableThumbnailProduct(context)
view.setProductInfo(item)
view.setOnProductChangeListener(onChangeListener())
rootLayout.setBackgroundColor(Color.TRANSPARENT)
rootLayout.addView(view)
}
}
Here is my XML
<HorizontalScrollView
android:id="#+id/scrollMed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none">
<LinearLayout
android:id="#+id/contentMed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#android:color/transparent"
android:descendantFocusability="beforeDescendants"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="horizontal" />
</HorizontalScrollView>
Here is my custom view
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#android:color/transparent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:orientation="vertical">
<ImageView
android:id="#+id/img_thumbnail"
android:layout_width="150dp"
android:layout_height="120dp"
android:background="#color/gray_border"
android:scaleType="fitXY" />
<TextView
android:id="#+id/txt_product_name"
style="#style/DefaultTextTitle"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_margin="5dp"
android:ellipsize="end"
android:gravity="center"
android:maxLines="2"
android:text="#string/product_name_label" />
<TextView
android:id="#+id/txt_product_stock"
style="#style/DefaultTextSubTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:gravity="center"
android:text="#string/available_stock_label" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/gray_border" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:orientation="vertical">
<Button
android:id="#+id/btn_add_to_cart"
style="#style/WhiteTitle"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_margin="10dp"
android:background="#drawable/round_button_orange"
android:gravity="center"
android:text="#string/buy_button_label"
android:visibility="invisible" />
<RelativeLayout
android:id="#+id/layout_plus_minus"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_margin="10dp"
android:orientation="horizontal">
<ImageView
android:id="#+id/btn_minus"
style="#style/WhiteTitle"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentLeft="true"
android:background="#drawable/round_button_blue"
android:paddingLeft="5dp"
android:paddingTop="11dp"
android:paddingRight="5dp"
android:paddingBottom="11dp"
android:scaleType="fitXY"
app:srcCompat="#drawable/ic_minus" />
<ImageView
android:id="#+id/btn_delete"
style="#style/WhiteTitle"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentLeft="true"
android:background="#drawable/round_button_blue"
android:padding="3dp"
android:scaleType="fitXY"
android:visibility="invisible"
app:srcCompat="#drawable/ic_delete" />
<EditText
android:id="#+id/txt_cart_amount"
style="#style/LightTextTitle"
android:layout_width="50dp"
android:layout_height="match_parent"
android:layout_marginLeft="40dp"
android:layout_marginRight="10dp"
android:backgroundTint="#color/blue_text_color"
android:inputType="number"
android:maxLength="3"
android:paddingBottom="5dp" />
<ImageView
android:id="#+id/btn_plus"
style="#style/WhiteTitle"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:background="#drawable/round_button_blue"
android:gravity="center"
android:padding="5dp"
android:scaleType="fitXY"
android:textSize="16sp"
app:srcCompat="#drawable/ic_plus" />
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
All sugestion will be appreciate. Thanks in advance.
Related
I'm trying to create an android app with RelativeLayout inside a scroll view which has a TextView with scrollbar but every time I try to scroll the TextView, RelativeLayout gets scrolled.
I've also tried following solutions but nothing works:
https://www.viralandroid.com/2015/10/how-to-make-scrollable-textview-in-android.html
how to make a relative layout scrollable when it has many children views?
RelativeLayout Scrollable
*My layout looks almost similar to 3rd link but with more controls.
Following is the code for my layout
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical">
<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"
tools:context=".MainActivity"
android:scrollbars = "vertical">
<TextView
android:id="#+id/textView1"
android:layout_width="365dp"
android:layout_height="20dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="10dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:text="#string/text1" />
<EditText
android:id="#+id/editText1"
android:layout_width="365dp"
android:layout_height="40dp"
android:layout_below="#+id/textView1"
android:layout_alignParentStart="true"
android:layout_marginStart="10dp"
android:layout_marginEnd="5dp"
android:inputType="text"
android:text=""/>
<!-- Other Controls, about 15 of them -->
<TextView
android:id="#+id/testLogs"
android:layout_width="360dp"
android:layout_height="150dp"
android:layout_below="#+id/something"
android:layout_alignParentStart="true"
android:layout_marginStart="14dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="14dp"
android:background="#drawable/edit_text_background"
android:textColor="#color/editTestBorderColor"
android:enabled="true"
android:gravity="bottom"
android:hint="Process logs"
android:scrollbars="vertical"
android:textIsSelectable="true"
android:focusable="true"
android:longClickable="true"
android:textSize="10dp" />
<Button
android:id="#+id/btnExecuteTest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/editTextLogs"
android:layout_alignParentStart="true"
android:layout_marginStart="67dp"
android:layout_marginTop="10dp"
android:text="#string/btnExecute" />
</RelativeLayout>
</ScrollView>
Problem : Unable to scroll Textview (android:id="#+id/testLogs")
Somehow if I have less controls(as long as layout's scrollable is not activated) then TextView's scroll is working.
Following are the device specs. that I'm using for testing :
Name : Huawei P10 lite
OS : Android 8.0
I have no idea why TextView scroll si not working?
Help Please!
try this
in XML file
android:maxLines = "AN_INTEGER"
android:scrollbars = "vertical"
and in java
tv_desc.setMovementMethod(new ScrollingMovementMethod());
scrollview.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
tv_desc.getParent().requestDisallowInterceptTouchEvent(false);
return false;
}
});
tv_desc.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
tv_desc.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});
Please do not mind for coding structure... Thank you.
in your layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/ScrollView01"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
tools:context=".MainActivity">
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="10dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:text="Enter SSID" />
<EditText
android:id="#+id/editText1"
android:layout_width="365dp"
android:layout_height="40dp"
android:layout_below="#+id/textView1"
android:layout_alignParentStart="true"
android:layout_marginStart="10dp"
android:layout_marginEnd="5dp"
android:inputType="text"
android:text="" />
<!-- Other Controls, about 15 of them -->
<androidx.core.widget.NestedScrollView
android:id="#+id/scroll1"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="#+id/editText1"
android:layout_marginTop="50dp"
android:fillViewport="false"
android:isScrollContainer="false">
<TextView
android:id="#+id/testLogs"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_below="#+id/editText1"
android:layout_alignParentStart="true"
android:background="#color/colorPrimary"
android:enabled="true"
android:focusable="true"
android:hint="Process logs"
android:longClickable="true"
android:scrollbars="vertical"
android:text="#string/sample_text"
android:textColor="#color/WindowBackground"
android:textIsSelectable="true"
android:textSize="14sp" />
</androidx.core.widget.NestedScrollView>
<Button
android:id="#+id/btnExecuteTest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/scroll1"
android:layout_alignParentStart="true"
android:layout_marginStart="134dp"
android:layout_marginTop="10dp"
android:text="Execute Test" />
<!--This is Additional code bellow -->
<!-- if you want to view multiple TextView with scrollable -->
<androidx.core.widget.NestedScrollView
android:id="#+id/scroll2"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="#+id/btnExecuteTest"
android:layout_marginTop="50dp"
android:fillViewport="false"
android:isScrollContainer="false">
<TextView
android:id="#+id/textView99"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="#+id/btnExecuteTest"
android:text="#string/sample_text" />
</androidx.core.widget.NestedScrollView>
<androidx.core.widget.NestedScrollView
android:id="#+id/scroll3"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="#+id/scroll2"
android:layout_marginTop="50dp"
android:fillViewport="false"
android:isScrollContainer="false">
<TextView
android:id="#+id/textView100"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="#+id/textView99"
android:text="#string/sample_text" />
</androidx.core.widget.NestedScrollView>
</RelativeLayout>
</ScrollView>
in you activity:
OnCreate():
TextView textView = findViewById( R.id.testLogs );
TextView textView1 = findViewById( R.id.textView99 );
TextView textView2 = findViewById( R.id.textView100 );
textView.setMovementMethod( new ScrollingMovementMethod( ) );
textView1.setMovementMethod( new ScrollingMovementMethod( ) );
textView2.setMovementMethod( new ScrollingMovementMethod( ) );
Preview:
Picture 1:
Picture 2:
Following is my xml layout.
<android.support.v7.widget.CardView
android:id="#+id/container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/colorPrimary"
app:cardBackgroundColor="#color/colorPrimary"
app:cardElevation="8dp"
app:layout_anchor="#id/contentMain"
app:layout_anchorGravity="right|bottom|end"
card_view:cardCornerRadius="4dp"
android:clickable="true"
android:focusable="true"
android:foreground="?android:selectableItemBackground">
<FrameLayout
android:id="#+id/bottomMargin"
android:layout_width="match_parent"
android:layout_height="70dp">
<ProgressBar
android:id="#+id/customProgress"
android:layout_width="match_parent"
android:layout_height="5dp"
android:visibility="visible"/>
<android.support.v7.widget.Toolbar
android:id="#+id/smallPlayer_home"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_alignParentTop="true"
android:layout_marginBottom="0dp"
android:visibility="visible">
<CircleImageView
android:id="#+id/selected_track_image_sp_home"
android:layout_width="54dp"
android:layout_height="54dp"
android:layout_alignParentStart="true"
android:layout_below="#+id/myvisualizerview"
android:layout_marginLeft="0dp"
android:layout_marginTop="10dp"
android:src="#drawable/album1"
android:visibility="visible"
app:civ_border_color="#FF000000"
app:civ_border_width="0dp"/>
<TextView
android:id="#+id/selected_track_title_sp_home"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_above="#+id/player_control"
android:layout_alignParentStart="true"
android:layout_marginLeft="35dp"
android:layout_marginTop="2dp"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="Title"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="13dp"/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_gravity="right|center_vertical"
android:layout_marginBottom="5dp"
android:layout_marginRight="17dp"
android:layout_marginTop="2dp"
android:background="?attr/selectableItemBackgroundBorderless">
<ImageView
android:id="#+id/player_control_sp_home"
android:layout_width="24dp"
android:layout_height="24dp"
android:clickable="true"
android:src="#drawable/ic_play_animatable"
android:visibility="visible"/>
<View
android:id="#+id/bufferingIndicatorMain"
android:layout_width="24dp"
android:layout_height="24dp"
android:clickable="true"
android:visibility="invisible"
app:indicator="BallSpinFadeLoader"
app:indicator_color="#FFFFFF"/>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
</FrameLayout>
</android.support.v7.widget.CardView>
Im using the following code to set On click listener for the cardview,
bottomCard.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
showFragment("streaming");
}
});
The problem is that the cardview click event is not getting fired.
I have also tried setting onFocusChangedListener upon cardview but still the onClick event is not getting fired.
How can I be able to sort this out?
You should set click listener for layout inside your cardview that is frame layout.You can try putting clickable property too like this
android:clickable = "true"
Also can refer this answer and this answer
Follow Shalini's answer or,
set clickable and focusable to false for inner layout (in your case bottomMargin FrameLayout), and set clickable and focusable to true for the CardView, as you already did.
I am using coardinate layout with recyclerview in viewpager and tablayout. I have a view for banner which i want to show over the recyclerview at the bottom. This bottom view is only visible if i scroll up the recyclerview list and hides when i scrollback down.I want this view to be visible all the time over recyclerview. Any help will be appreciated. Thanks in advance.r image description here]1]1
Here is my xml code
<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="#color/deal_display_bg"
tools:context="com.safar.spicedeals_activities.DealsActivity$PlaceholderFragment">
<View
android:id="#+id/topview_deal"
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_alignParentTop="true"
android:background="#color/spice_laddooblue"
android:visibility="gone" />
<View
android:layout_width="match_parent"
android:layout_height="5dp" />
<TextView
android:id="#+id/no_deals_available"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="#string/no_deals_available"
android:textColor="#color/spice_laddooblue"
android:textSize="18sp"
android:textStyle="bold"
android:visibility="gone" />
<FrameLayout
android:id="#+id/frameLayoutDeals"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/bannerView"
android:layout_below="#+id/topview_deal"
android:padding="2dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ProgressBar
android:id="#+id/progressBarDeals"
style="?android:attr/android:progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="visible" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- </android.support.v4.widget.SwipeRefreshLayout> -->
</FrameLayout>
<RelativeLayout
android:id="#+id/relativeLayout_PriceTotal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#drawable/background_with_border_square"
android:padding="10dp"
android:visibility="gone">
<TextView
android:id="#+id/textView_totalPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="#string/total_price"
android:textColor="#color/spice_laddooblue"
android:textSize="15sp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView_totalPriceResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignTop="#+id/textView_totalPrice"
android:layout_marginLeft="3dp"
android:layout_marginTop="2dp"
android:layout_toRightOf="#+id/textView_totalPrice"
android:textColor="#color/spice_laddooblue"
android:textSize="15sp"
android:textStyle="bold" />
<Button
android:id="#+id/button_processDeal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textView_totalPrice"
android:layout_marginTop="10dp"
android:background="#color/spice_laddooblue"
android:text="#string/proceed_tag"
android:textColor="#color/White"
android:textStyle="italic" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/bannerView"
android:layout_width="match_parent"
android:layout_height="58dp"
android:layout_alignParentBottom="true"
android:background="#drawable/curved_white_with_blue_border"
android:visibility="gone">
<TextView
android:id="#+id/bannerText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:gravity="center"
android:padding="3dp"
android:text="Banner"
android:visibility="gone" />
<ImageView
android:id="#+id/bannerImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center"
android:padding="3dp"
android:scaleType="fitXY"
android:visibility="gone" />
<ImageView
android:id="#+id/bannerClose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_centerVertical="true"
android:src="#drawable/cross_icon" />
</RelativeLayout>
</RelativeLayout>
This worked for me! add this attribute for your android.support.v7.widget.Toolbar
app:layout_scrollFlags="scroll"
The app:layout_scrollFlags attribute of the Toolbar indicates to the view how to respond. It has the following possible values.
scroll :
This flag is generally set for all views that need to
scroll off-screen. Views that don’t use this flag remain static
allowing the other scrollable views to slide behind it.
enterAlways :
This flag ensures that any downward scroll will cause the view to
become visible, enabling the quick return pattern.
enterAlwaysCollapsed :
An additional flag for ‘enterAlways’ which
modifies the returning view to only initially scroll back to it’s
collapsed height.
exitUntilCollapsed :
This flag causes the view to
be scrolled until it is collapsed (its minHeight is reached) before
exiting
snap : Upon a scroll ending, if the view is only partially
visible then it will be snapped and scrolled to it’s closest edge.
Hence this avoids mid-animation states of a view
More details can be found here.
I am using a RecyclerView and I am not able to see any feedback when I touch on the item of the RecyclerView. How do I achieve it?
I am trying to show a feedback to the user when they are touching the row of RecyclerView. Something like a ripple effect.
I want to know how to achieve it in a specific row of the RecyclerView.
This is the recycler view's custom row layout.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/drawer_row"
android:background="?android:attr/selectableItemBackground"
android:clickable="true">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="30dp"
android:layout_marginStart="30dp"
android:layout_toEndOf="#+id/navigation_image"
android:layout_toRightOf="#+id/navigation_image"
android:textSize="17sp" />
<ImageView
android:id="#+id/navigation_image"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginLeft="30dp"
android:layout_marginStart="30dp" />
<TextView
android:id="#+id/horizontal_line"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignParentBottom="true"
android:background="#F1F1F1" />
</RelativeLayout>
This is the layout of the Activity having the RecyclerView
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/windowBackground">
<RelativeLayout
android:id="#+id/nav_header_container"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_alignParentTop="true"
android:background="#drawable/ic_drawer_header">
<ImageView
android:id="#+id/circle_imageview"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="#drawable/profile_pic"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="John Doe"
android:textSize="20sp"
android:textColor="#ffffff"
android:layout_below="#+id/circle_imageview"
android:layout_alignLeft="#+id/circle_imageview"
android:layout_alignStart="#+id/circle_imageview"
android:layout_marginTop="5dp" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Transaction Technologies"
android:layout_below="#+id/textView"
android:layout_alignLeft="#+id/textView"
android:layout_alignStart="#+id/textView"
android:textColor="#ffffff"
android:layout_marginTop="5dp" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/drawerList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/nav_header_container" />
</RelativeLayout>
I just need to highlight/give feedback of the row which is being touched by the user. How do I achieve it?
Thanks in advance.
You need to add android:focusable="true" in your custom row item for RecyclerView
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/drawer_row"
android:background="?android:selectableItemBackground"
android:focusable="true"
android:clickable="true" >
</RelativeLayout>
You can add a Ripple effect by using THIS LIBRARY.Include it in your Gradle files using.
compile 'com.thomsonreuters:rippledecoratorview:+'
Simply put your row layout in a RippleDecoratorView.For eg:
<com.thomsonreuters.rippledecoratorview.RippleDecoratorView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="4dp"
rdv:rdv_rippleColor="#android:color/holo_blue_dark"
rdv:rdv_rippleAnimationFrames="60"
rdv:rdv_rippleAnimationPeakFrame="15"
rdv:rdv_rippleMaxAlpha="0.8"
rdv:rdv_rippleAnimationDuration="600"
rdv:rdv_rippleRadius="50dp">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/drawer_row"
android:background="?android:attr/selectableItemBackground"
android:clickable="true">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="30dp"
android:layout_marginStart="30dp"
android:layout_toEndOf="#+id/navigation_image"
android:layout_toRightOf="#+id/navigation_image"
android:textSize="17sp" />
<ImageView
android:id="#+id/navigation_image"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginLeft="30dp"
android:layout_marginStart="30dp" />
<TextView
android:id="#+id/horizontal_line"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignParentBottom="true"
android:background="#F1F1F1" />
</RelativeLayout>
</com.thomsonreuters.rippledecoratorview.RippleDecoratorView>
Or you can use any of these libs acc to your requirement:
1>https://github.com/balysv/material-ripple
2>https://github.com/siriscac/RippleView
3>https://github.com/traex/RippleEffect
I can help you but I will need some feedback from you as well. In the onCreateVIewHolder inside your recycler View adapter you must have defined textViews and assigned it to the elements inside the sample recycler view. Add this. Make sure you define the layout outside the function so its accessible throughout the class
RelativeLayout layout;
layout=(RelativeLayout)view.findViewById.(R.layout.drawer_row)
Then go to you recycler view adapter and in the onBindViewHolder define
holder.layout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Handle onClick event
}
});
In the onClick event you can add any kind of feedback you want to the user to experience such as starting a new activity, toasts, messages or in this case a ripple effect. You can use a custom library for ripples such as these
Ripple effect for lollipop views
https://android-arsenal.com/details/1/980
https://github.com/balysv/material-ripple
Ripple effects are not supported in pre-Lollipop devices.
Still use this material-ripple
compile 'com.balysv:material-ripple:1.0.2'
Apply ripple on holder.drawView
MaterialRippleLayout.on(holder.drawerView)
.rippleColor(Color.RED)
.create();
Or you can apply from xml
<com.balysv.materialripple.MaterialRippleLayout
android:id="#+id/ripple"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Button inside a ripple"/>
</com.balysv.materialripple.MaterialRippleLayout>
I have an EdiText at the bottom of my layout.The issue I was having is that when it gets focus the screen shifts upwards to give space to soft keyboard.To resolve it I added
android:windowSoftInputMode="adjustResize"
inside my Activity declaration in manifest.Now the problem is that the edittext hides behind the softkeyboard although screen doesn't shifts.
If instead I put
android:windowSoftInputMode="adjustPan"
then the activity's main window shifts upward which i don't want.
How can i resolve this in such way that when EdiText gets focus activity's main window does NOT shift upwards to make room for the soft keyboard but the main window is resized including the EdiText so that keyboard comes below EdiText as seen in many apps.
Layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/background_feed">
<ProgressBar
android:id="#+id/progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center_horizontal|center_vertical" />
<ListView
android:id="#+id/comments"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F7F7F7"
android:paddingTop="10dp"
android:layout_above="#+id/border_view_comment"
android:divider="#android:color/transparent"
android:dividerHeight="10dp"
android:paddingBottom="10dp"
android:clipToPadding="false"
android:scrollbarStyle="outsideOverlay" />
<TextView
android:id="#+id/empty_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="#string/no_comment_msg"
android:visibility="gone"/>
<View
android:id="#+id/border_view_comment"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_above="#+id/commentlayout"
android:background="#C7C7C7"
android:visibility="gone"/>
<RelativeLayout
android:id="#+id/commentlayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#drawable/comment_box_shadow"
android:padding="10dp">
<ImageView
android:id="#+id/commentor_image"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginRight="15dp"
/>
<ImageView
android:id="#+id/clickPostComment"
android:layout_width="30dp"
android:layout_height="45dp"
android:layout_alignParentRight="true"
android:src="#drawable/post"
android:textColor="#color/white" />
<EditText
android:id="#+id/commentsPost"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_alignTop="#id/commentor_image"
android:layout_marginRight="10dp"
android:layout_toLeftOf="#id/clickPostComment"
android:layout_toRightOf="#id/commentor_image"
android:background="#drawable/comment_edittext_bg"
android:hint="Comments"
android:singleLine="true"
android:maxLength="140"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#color/title_gray"
android:textColorHint="#d5d5d5"
android:textSize="15sp" />
<ImageView
android:layout_width="25dp"
android:layout_height="30dp"
android:layout_alignTop="#id/commentsPost"
android:layout_marginLeft="10dp"
android:layout_marginRight="-2dp"
android:layout_toLeftOf="#id/commentsPost"
android:scaleType="fitStart"
android:src="#drawable/comment_shape" />
</RelativeLayout>
</RelativeLayout>
make your view scrollable by embed your view inside Scrollview
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content" >
.....
add your layout
......
</ScrollView>
If that doesn't help make you root layout as RelativeLayout and design your layout with RelativeLayout