android-view

Why do we have to add 'View' as parameter in onClick method and what it does?

拥有回忆 提交于 2019-12-10 11:00:29
问题 I'm setting up a Event Listener on a Button in Android Studio for changing the text inside the TextView and came to this point were we define OnClick method. In its parameter list it ask for View Object. Can anyone explain what it does? I can't understand where the object of View class is going to get used. 回答1: It is there to let you reuse event handlers like the OnClick method, the View parameter is in your case the Button instance that has fired the method - multiple Buttons can have the

Instantiating a View on non-UI thread

纵饮孤独 提交于 2019-12-10 10:17:14
问题 I know that the UI elements (View hierarchy) may only be manipulated from the UI thread. For a background operation, the AsyncTask can be used, which offers event handlers to reach the UI thread. To be brief, is it allowed to instantiate a View (tied to getApplicationContext() ) in a non-UI thread? This custom View descendant -- once instantiated -- is added to the view hierarchy from the UI thread . So only the constructor call is done inside an Asynctask.doInBackground() ; it's attaching (

MPAndroidChart Bar Chart - how to group bars with random x-axis intervals in between groups?

断了今生、忘了曾经 提交于 2019-12-10 10:08:37
问题 I want to make a bar chart with 3 different datasets grouped together at each data point like so: However, I am unable to group the bars together using the library's provided groupBars method because no matter what x-value I set for an entry, it groups the bars according to the interval I specify in its parameters. For example, if I generate a dataset with entry x-values {0, 5, 13, 17...50} and call `groupBars', all of my entries are gathered 1 x-value apart like so: What I want is the bars

Measure Recyclerview before it appears

前提是你 提交于 2019-12-10 03:52:29
问题 I am currently experiencing an issue when measuring a recyclerView before it appears. I need the measuredHeight in order to start an "expand" animation. This was previously done for a gridView in the code I'm working on and I am trying to migrate it to a RecyclerView with GridLayoutManager final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); final int heightSpec = View.MeasureSpec.makeMeasureSpec(MEASURED_SIZE_MASK, View.MeasureSpec.AT_MOST); mGridView

Difference between foo.setVisibility(View.GONE) and parent.removeView(foo)

末鹿安然 提交于 2019-12-10 01:54:57
问题 If foo is a view, what is the difference between foo.setVisibility(View.GONE) and fooParent.removeView(foo) ? I am particularly interested in memory consumption of the view, before and after both statements. Does a view with visibility set to GONE consume memory ? 回答1: If you need to remove them and then show them again, it could be better to just set visibility to gone and then change back to visible again. If you on the other hand don't need them visible again, simply remove them. 回答2:

Android - How do you efficiently load a large amount of text in a TextView?

我是研究僧i 提交于 2019-12-10 01:02:38
问题 I'm writing an Android app that reads a single text file and display it on a TextView . What I'm doing right now is read the whole file into a String (using BufferedReader and StringBuilder ) and display it on a TextView using setText(string) . A 700KB text file can take about 2 to 3 seconds before it is being displayed on the screen. But I've used some other ebook readers on the market and they can display the same text almost instantly. Anyone know how I can achieve this? Thanks you. Edit :

Tracking what all items of a list are currently visible on the screen

大城市里の小女人 提交于 2019-12-09 23:55:46
问题 Suppose I have a recyclerview with 10 items. Out of these 10, 0 - 4 are visible in one go. On scrolling down, 0th element goes away from the screen and 5th one enters. I want to track these events - where I get to know that elements 0 - 4 are visible and then on scrolling, 1-5 are. Is there anyway to achieve this? I want to keep track of how long a user is spending time on a particular items of the recyclerview. 回答1: set addOnScrollListener on RecyclerView and get first and last visible rows

How to stop Android ViewFlipper from looping?

允我心安 提交于 2019-12-09 18:16:38
问题 I have a ViewFlipper set to auto-flip every 5 seconds. Leaving out some of the details, it looks like this and works fine: ViewFlipper flipper = (ViewFlipper) findViewById(R.id.myflipperid); flipper.setFlipInterval(5000); flipper.setInAnimation(inFromRightAnimation()); flipper.setOutAnimation(outToLeftAnimation()); flipper.startFlipping(); However, I have a case where I want the auto-flipping to stop at the last view, rather than looping around to start over again. It doesn't seem that

How many WindowInsets are there?

风格不统一 提交于 2019-12-09 14:18:12
问题 I do not understand about WindowInsets rects, because docs says that: The system window inset represents the area of a full-screen window that is partially or fully obscured by the status bar, navigation bar, IME or other system windows. So, multiple WindowInsets can be there each with its own rect (one for status bar, another for Navigation Bar ...), and how can I retrieve them? Or is there only one WindowInsets and its left-top-right-bottom coordinates are the rect of the available window

Bottom navigation view with custom item (actionLayout)

浪尽此生 提交于 2019-12-09 09:45:21
问题 I would like to add a custom item in the new BottomNavigationView . There are plenty of tutorial of adding a custom view with the normal navigation view but I can't find anything regarding the bottom one. This is my view <android.support.design.widget.BottomNavigationView android:id="@+id/navigation_view" android:layout_width="match_parent" android:layout_height="wrap_content" app:menu="@menu/menu_main" /> And this is the menu <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http:/