I have a custom rating bar in which i edited from this tutorial (http://kozyr.zydako.net/2010/05/23/pretty-ratingbar/)
I only want to show full cookies and not empty ones hence i replaced the empty-cookie.png with just a transparent image.
My problem is, in my UI i want my visible cookies to be right aligned, in other words, to be shown from right to left instead of the current left to right.
How can i achieve that? i DO NOT NEED to show half cookies and this is only used as an indicator (android:isIndicator="true")
Alternate non-ratingbar solutions are welcomed too. :)
i solved this by setting visibilities of multiple ImageViews stored in an array and displayed using a RelativeLayout in the end.
private void setClocksVisible(int numClocks) {
if(numClocks == 0 || numClocks == -1) {
for(int i=0; i< holder.ratingClocks.length; i++) {
holder.ratingClocks[i].setVisibility(View.INVISIBLE);
}
} else {
for(int i=0; i<numClocks; i++) {
holder.ratingClocks[i].setVisibility(View.VISIBLE);
}
}
}
Related
I have a layout for recyclerview adapter that it's like a instagram. That means it has a slider for images and like button and etc.
Now I want to load multiple images in the slider and clients should change images with dragging like instagram exactly.
First I used PosterSlider library, but its problem is that doesn't have scale type so I cannot manage images size.
So now I wanna try ViewFLipper, but my problem is I don't know how can I use ViewFlipper like a slider.
That means how can I change images by dragging in ViewFLipper?
If you have another idea for changing picture, I will be glad to hear it.
This is my code for ViewFlipper that I know it is wrong, because it shows just one Image and it doesn't have any code for changing picture by dragging:
try {
JSONArray jsonArray = new JSONArray(newsLetterList.get(position).Jsonsrc);
for(int i = 0;i < jsonArray.length(); i++){
setImageInFlipper(jsonArray.getString(i),holder);
}
} catch (JSONException e) {
e.printStackTrace();
}
setImageInFLipper method:
private void setImageInFlipper(String imgUrl,NewsLetterViewHolder holder){
ImageView imageView = new ImageView(context);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
Glide.with(context).load(imgUrl).into(imageView);
holder.slider.addView(imageView);
}
You can take some reference from here. They have implemented the same viewflipper slide both with next(flip) button and without using any button. Hope that helps!
I want to perform scroll using Accessibility service and i am doing this
public boolean scrollView(AccessibilityNodeInfo nodeInfo) {
if (nodeInfo == null) return false;
if (nodeInfo.isScrollable()) {
return nodeInfo.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
}
for (int i = 0; i < nodeInfo.getChildCount(); i++) {
if (scrollView(nodeInfo.getChild(i)) {
return true;
}
}
return false; }
But problem is when there are four option to perform up,down left and right it performs left and right but i want to perform up and down there also.
like in facebook app it scroll on top section where notifications and news feed are.But not on page.
is there any way to scroll where is focus of user.
You're probably scrolling the wrong container. There are likely multiple views in your heirarchy that are "scrollable". Try finding different scrollable views within your heirarchy.
Also, in Android M they added APIs to do things like specifically scroll different directions. So, if you are in fact on the correct View, you can scroll in different directions using these actions instead:
ACTION_SCROLL_FORWARD
ACTION_SCROLL_LEFT
ACTION_SCROLL_RIGHT
etc.
https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo.AccessibilityAction.html
I'm trying to create a One-armed Bandit app.
I have created an animation xml file to go through multiple images. When a button is clicked, the animation stops.
My question is how to compare the picture that one animation stopped on with that of another? So far I've tried something like this:
if(wheel1.getBackground().getConstantState().equals(wheel2.getBackground().getConstantState())) matches++;
Any help is appreciated.
you must be starting the animation with .animationStart()
just use .onAnimationStop() and it will trigger the event automatically.
A View should not maintain application logic, the controller (your hosting Activity or Fragment) should.
That said, to achieve what you want use View.setTag() to apply a logical description of each View to it.
Then when stopping animation, loop through all Views you have and get their position on screen, get the Views mostly visible in each column of your bandit machine and compare their tags (View.getTag())
for example, if the items animate vertically use below method to determine where the bandit stopped.
//the area where to compare views
int BOUND_TOP, BOUNT_DOWN;
//your content view
ViewGroup rootLayout;
//method to get information about what is visible
public List<Object> getVisibleViewTags() {
List<Object> list = new LinkedList<>();
int count = rootLayout.getChildCount();
for (int pos = 0; pos < count; pos++) {
View child = rootLayout.getChildAt(pos);
float translationY = child.getTranslationY();
if (translationY > BOUND_TOP && translationY < BOUND_DOWN) {
list.add(child.getTag());
}
}
return list;
}
Now you just need to attach information about a view as tag to it.
example:
view.setTag("view_apples");
or
view.setTag("view_bananas");
Part of application I'm currently working on act exactly as android shell, shows several pages filled with icons with text labels. User could slide between pages to find needed element. I'm using PagerView with GridView in each page.
Content of each page should fit exactly of visible area, no scroll. The question how to calculate number of icons on each page?
The issue next, I can't call pagerView.getHeight(), I'll have 0 in result because actual layout calculation wasn't executed yet.
UPDATED:
Seems I wasn't able to describe my problem well, I'll try to provide more simple case, suppose I do have activity with status bar at the top and some button bar at the bottom, both fixed height. Whole remaining area in the middle is used by GridView.
Grid view should show rectangular icons, and what I need to calculate is how many icons it could show without scroll (because remaining icons will be shown on next activity).
You can try something like:
public int countElements(ViewGroup group) {
int count = 0;
for (int i = 0; i < group.getChildCount(); i++) {
View v = layout.getChildAt(i);
Class c = v.getClass();
if (c == *Icon*) {
count++;
}
}
return count;
}
In case you have inner views you can check if c is a GroupView and call the method recursively.
As for your second issue, try using this in onCreate:
private void calculateSize(int height, int width){
int rows = Math.floor(height/imageHeight);
int columns = Math.floor(width/imageWidth);
//do something with numbers
}
ViewTreeObserver vto = pagerView.getViewTreeObserver();
if(vto.isAlive()){
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
vto.removeGlobalOnLayoutListener(this);
calculateSize(gridView.getHeight(), gridView.getWidth());
}
});
}
I have a gridview that is made of of 31 cells. A user can select any combination of cells and then click on a button to save their selections. Once they click the save button a dialog box appears and asks them what they want to do next. Within this dialog is a edit text view. When the user clicks inside the edit text box the keyboard appears. When this happens only 21 of the 31 cells are visible on the screen and when I try to call the getChildrenCount() method of GridView class I only see 21 children. Can someone explain why this happens and what I can do to eliminate this issue? I have attached images in hopes that clarifies the issue. Below I have pasted a snippet of code where I am trying to get the child count of the gridview.
protected Set<String> getSelectedFrequencies() {
Set<String> selectedFrequencies = new HashSet<String>();
for(int i = 0; i < gridView.getChildCount(); i++) {
ViewGroup gridChild = (ViewGroup) gridView.getChildAt(i);
for(int k = 0; k < gridChild.getChildCount(); k++) {
if( gridChild.getChildAt(k) instanceof Button ) {
if(gridChild.getChildAt(k).isSelected()) {
selectedFrequencies.add(gridChild.getChildAt(k).getTag().toString());
}
}
}
}
return selectedFrequencies;
}
There is nothing really special about the code.
Are you using a softInputMode of pan or resize? With pan that will never happen. With resize, it could be that only 21 fit on screen, so the gridView creates only 21 children and does view swapping when you scroll. In case you didn't know, listview and gridview only create as many views as are needed to fit on the screen. When you scroll it just loads data for the new positions into the existing views.