I want to create a "focus" effect once the user clicks an item in the recycler view. Look at the image below, the second one is the effect I wish to have.
I've tried to get the RecyclerView's clicked item and bring it to the front and show a dark/transparent overlay covering all the others.
This is my view hierarchy:
RelativeLayout
--- Recycler View
--- View (dark overlay)
I've tried with view.bringToFront();, view.setZ();, view.setElevation(); but none of them works.
Now I guess this is about the layout hierarchy. How to solve this problem?
you can just change the background color of touch item view and text color. when user click on it .
I achieved this effect by sending the item view to the Window.DecorView.
You can just make a copy of the desired view you want to put in the front (in this case you want the layout used by the ViewHolder) and then
((ViewGroup)activity.getWindow().getDecorView()).addView(yourView);
after that you can set Translations according to the original view. The new view will be in front of the dark overlay in the same place the previous view is
EDIT: I have a sample of what you can do:
The following code is C# (using Xamarin.Android), it should be easy to turn to Java.
var productView = productsLayoutManager.FindViewByPosition(position);
var cardView = productView.FindViewById<CardView>(Resource.Id.product_layout);
int[] location = new int[2];
productView.GetLocationOnScreen(location);
int left = location[0];
int top = location[1];
selectedView = LayoutInflater.Inflate(Resource.Layout.ProductRow2, null);
productsAdapter.CloneItemViewHolder(productView, ref selectedView);
selectedView.LayoutParameters = new FrameLayout.LayoutParams(cardView.LayoutParameters);
((ViewGroup)activity.Window.DecorView).AddView(selectedView, cardView.Width, cardView.Height);
selectedView.SetX(left);
selectedView.SetY(top);
selectedView.RequestLayout();
activity.DimBackground();
The cardView is the main layout of the RecyclerView item Viewholder.
This is actual code in use, producing this:
Related
I have bunch of text view and edit text form inside a scroll view and also having a linear Layout below form inside same scroll view in this linear layout having bunch of text view vertical. Initially linear layout has visibility gone when user press "add more info",which is aling just above this linear layout, button then layout visibility is Visible. This is working fine as expected but what i want is when linear layout get visible then scroll view should scroll down so that user can see the extended data. I tried all but nothing can help me.
Please help me to solve this.Below is ShowHideLayout method.
Need Help
fun showHideLayout() {
if (linearLayoutAddMoreInfoExpand.visibility == GONE) {
linearLayoutAddMoreInfoExpand.visibility = VISIBLE
mTextViewAddMoreInfo.setText("Close Add More Info")
scrollView.post(Runnable {
scrollView.fullScroll(ScrollView.FOCUS_DOWN)
//scrollView.scrollTo(0,scrollView.bottom)
})
// scrollView.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
scrollView.scrollTo(0,scrollView.bottom)
//scrollView.smoothScrollBy(R.id.linearLayoutAddMoreInfoExpand,R.id.scrollBottom)
} else if (linearLayoutAddMoreInfoExpand.visibility== VISIBLE) {
linearLayoutAddMoreInfoExpand.visibility = GONE
mTextViewAddMoreInfo.setText("+ Add More Info")
}
}
You can solve this adding another scrollview before your exapandLinearLayout in xml file and call this scrollview on button click so your whenever your linear layout is it will scroll down. But it may not be best practice.
Your code will be like below
<Scrollview
android:id = #+id/scrollViewLayout
.....
....>
<LinearLayout....>
<--Remaining view-->
</LinearLayout>
</Scrollview>
And in Java on addmoreinfo button click call this scrollview like below:-
fun showHideLayout() {
if(linearLayoutAddMoreInfoExpand.visibility == GONE){
linearLayoutAddMoreInfoExpand.visibility = VISIBLE
mTextViewAddMoreInfo.setText("Close Add More Info")
scrollViewLayout.post(Runnable { scrollView.fullScroll(ScrollView.FOCUS_DOWN) })
im a android developer and need to do this:
Recycler view horizontal like facebook
enter image description here
Thats one recyclerview horizontal with a tablayout, i wanna do is while the user be scrolling de recycler view his cannot swipe the tab layout.
Like facebook tab videos
Create a recyclerView in the xml and add this code in the activity. You will achieve the horizontal scrolling without swiping the tab layout.
adapter = new Adapter(// pass your arguments);
layoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
recycleView.setLayoutManager(layoutManager);
recycleView.setAdapter(adapter);
recycleView.setNestedScrollingEnabled(false);
I've been trying to get a widget from another layout for past hours but still no luck. Can someone tell what is wrong with my current code?
public void refreshClicked(View view){
tab1 = LayoutInflater.from(view.getContext()).inflate(R.layout.tab_1, null);
Button b = (Button) tab1.findViewById(R.id.refresh);
b.setText("Updating...");
}
I've hooked my button onClick to refreshClicked(View view) method.
This method is under my MainActivity.java and I'm trying to get the Button with id refresh from tab_1.xml layout but the button text is not updating.
Thanks!
You seems to inflate a layout but never attach it to a parent view as the ViewGroup parameter is null. Then this layout inflated must not even been displayed anywhere.
If the button b already exists, no need to inflate the layout and retrieve the button form there, it will a different button.
Just retrieve the button from the actual existing layout.
Check out this picture:
WhoKnew title and WK? Icon http://puu.sh/5Ejo5.png
See the icon and title there? How do I go about removing that?
I'm not using any of the drag and drop or xml editing at all in eclipse for this project, because I have to dynamically create an arbitrary amount of buttons/text, and whatnot.
Basically, I've been going about it by doing something like this..
public createMainMenu(){
//make layout
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setBackgroundColor(backgroundColor);
//make/add text to layout
menuText.setText("Who Knew?");
menuText.setId(20001);
menuText.setTextSize(36);
menuText.setTextColor(textColor);
layout.addView(menuText);
//make a scrollview, then add the layout to the scrollview
ScrollView sc = new ScrollView(this);
sc.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
sc.setFillViewport(true);
sc.addView(layout);
//set content view to the scrollview
setContentView(sc);
}
Hopefully, I'm on the right track here on how I should be going about this. The app I have is working fine, I just need to get rid of that icon/title bar, if possible. I guess it's not a gamebreaker, but it's a bit annoying.
you can use this in your java class
requestWindowFeature(Window.FEATURE_NO_TITLE);
Add this to your manifest:
android:theme="#android:style/Theme.Light.NoTitleBar"
I have been following this guide and i have it running.
http://www.mkyong.com/android/android-tablayout-example/
I have added a bunch of new widgets to the tabs using java (image views and text fields) but its getting messy and i dont have as much control over the positioning and size as i would like to have since i cant use layouts
If i created a new layout using xml and i placed all my widgets perfectly using layouts etc is there a way i can populate a specific tab with that layout using java?
eg
rather than have code like this to add widgets
TextView textview = new TextView(this);
textview.setText("This is Android tab");
setContentView(textview);
i can just add a reference to an xml file and it will add all them widgets within the xml file
Use LayoutInflater http://developer.android.com/reference/android/view/LayoutInflater.html
LayoutInflater inflater = LayoutInflater.from(context); // if you're inside of activity then context = this
View viewInflatedFromXml = inflater.inflate(R.layout.your_layout, null);
Then you can do what you want with this view.