问:
Postgresql query to find top voted tables within last 24 hours
I have a complex PostgreSQL DB query that I am having difficulties constructing. I have two tables: a post table and a votes table. Below is what they look like:

The post table- I've only included the id because other columns aren't important to my question

```<code> ----
| id |
 ----
</code>```

The votes table- vote_type can either be 1 (upvote), -1 (downvote), or 0 (neutral). The post_id is the id of the id of the post for the single vote.

```<code> ---- --------- ----------- --------------------------------
| id | post_id | vote_type | timestamp                      |
 ---- --------- ----------- --------------------------------
| 1  | 4       | 1         |  2017-03-30 12:17:12.246765-07 |
</code>```

Here's what I am trying to achieve: Query top 10 posts with the most votes within the last 24 hours

I've first constructed the following query:

```<code>SELECT postsTable.*, votesTable.votes
FROM posts AS postsTable
RIGHT JOIN (
  SELECT sum(vote_type) votes, post_id
  FROM votes
  WHERE (extract(day from age(now(), timestamp)) < 1)
  GROUP BY post_id)
  AS votesTable
  ON (postsTable.id = votesTable.post_id)
ORDER BY votes DESC NULLS LAST LIMIT 10;
</code>```

Returns something like:

```<code> ---- ---------------------- -------
| id | other_colums_between | votes |
 ---- ---------------------- -------
| 8  | ...                  | 1     |
</code>```

It works slightly with the right posts BUT the votes column only shows the sum of votes within the last 24 hours NOT the total votes made since the post has been made (and that's what I want). The reason is because I am summing the votes only made within the last 24 hours and NOT all votes since the post has been created.

Say the post with id 8 has 10 votes. The query only returns 1 vote because only one upvote has been made within the last 24 hours.

Thus the query should return:

```<code> ---- ---------------------- -------
| id | other_colums_between | votes |
 ---- ---------------------- -------
| 8  | ...                  | 10    |
</code>```

So I know what I have to fix but I don't know how to do it. I've tried the query below but it's not what I want but I feel like I am getting closer. I haven't included the filtering for posts within the last 24 hours on this one though.

```<code>SELECT postsTable.*, votesTable.vote_type, extract(day from age(now(), votesTable.timestamp)) age
FROM posts AS postsTable
RIGHT JOIN (SELECT * FROM votes)
AS votesTable ON (postsTable.id = votesTable.post_id)
ORDER BY vote_type DESC NULLS LAST LIMIT 10;
</code>```

Returns:

```<code> ---- ---------------------- ----------- -----
| id | other_colums_between | vote_type | age |
 ---- ---------------------- ----------- -----
| 8  | ...                  | 1         | 3   |
</code>```

As you can tell I am a beginner in SQL. I also ask for some advice as to how I can simplify the queries above. Thank you for your help.

答:
I can just think of this, but I haven't tested.</p>

```<code>SELECT postsTable.*, votesTable.votes FROM posts AS postsTable RIGHT JOIN ( SELECT sum(vote_type) votes, post_id FROM votes WHERE votes.post_id IN (select unique v.post_id  from votes as v where( extract(day from age(now(), timestamp)) < 1) ) GROUP BY post_id) AS votesTable ON (postsTable.id = votesTable.post_id) ORDER BY votes DESC NULLS LAST LIMIT 10;
</code>```

Body:
I have a complex PostgreSQL DB query that I am having difficulties constructing. I have two tables: a post table and a votes table. Below is what they look like:

The post table- I've only included the id because other columns aren't important to my question

 ----
| id |
 ----

The votes table- vote_type can either be 1 (upvote), -1 (downvote), or 0 (neutral). The post_id is the id of the id of the post for the single vote.

 ---- --------- ----------- --------------------------------
| id | post_id | vote_type | timestamp                      |
 ---- --------- ----------- --------------------------------
| 1  | 4       | 1         |  2017-03-30 12:17:12.246765-07 |

Here's what I am trying to achieve: Query top 10 posts with the most votes within the last 24 hours

I've first constructed the following query:

SELECT postsTable.*, votesTable.votes
FROM posts AS postsTable
RIGHT JOIN (
  SELECT sum(vote_type) votes, post_id
  FROM votes
  WHERE (extract(day from age(now(), timestamp)) < 1)
  GROUP BY post_id)
  AS votesTable
  ON (postsTable.id = votesTable.post_id)
ORDER BY votes DESC NULLS LAST LIMIT 10;

Returns something like:

 ---- ---------------------- -------
| id | other_colums_between | votes |
 ---- ---------------------- -------
| 8  | ...                  | 1     |

It works slightly with the right posts BUT the votes column only shows the sum of votes within the last 24 hours NOT the total votes made since the post has been made (and that's what I want). The reason is because I am summing the votes only made within the last 24 hours and NOT all votes since the post has been created.

Say the post with id 8 has 10 votes. The query only returns 1 vote because only one upvote has been made within the last 24 hours.

Thus the query should return:

 ---- ---------------------- -------
| id | other_colums_between | votes |
 ---- ---------------------- -------
| 8  | ...                  | 10    |

So I know what I have to fix but I don't know how to do it. I've tried the query below but it's not what I want but I feel like I am getting closer. I haven't included the filtering for posts within the last 24 hours on this one though.

SELECT postsTable.*, votesTable.vote_type, extract(day from age(now(), votesTable.timestamp)) age
FROM posts AS postsTable
RIGHT JOIN (SELECT * FROM votes)
AS votesTable ON (postsTable.id = votesTable.post_id)
ORDER BY vote_type DESC NULLS LAST LIMIT 10;

Returns:

 ---- ---------------------- ----------- -----
| id | other_colums_between | vote_type | age |
 ---- ---------------------- ----------- -----
| 8  | ...                  | 1         | 3   |

As you can tell I am a beginner in SQL. I also ask for some advice as to how I can simplify the queries above. Thank you for your help.

Body:
I can just think of this, but I haven't tested.

SELECT postsTable.*, votesTable.votes FROM posts AS postsTable RIGHT JOIN ( SELECT sum(vote_type) votes, post_id FROM votes WHERE votes.post_id IN (select unique v.post_id  from votes as v where( extract(day from age(now(), timestamp)) < 1) ) GROUP BY post_id) AS votesTable ON (postsTable.id = votesTable.post_id) ORDER BY votes DESC NULLS LAST LIMIT 10;


来源: stackexchange

问:
How to transform a projected 3D rectangle into a 2D axis aligned rectangle
I have an image of a 3D rectangle (which due to the projection distortion is not a rectangle in the image). I know the all world and image coordinates of all corners of this rectangle.

What I need is to determine the world coordinate of a point in the image inside this rectangle. To do that I need to compute a transformation to unproject that rectangle to a 2D rectangle.

How can I compute that transform?

Thanks in advance

答:
If I understand you correctly, you have a 2D point in the projection of the rectangle, and you know the 3D (world) and 2D (image) coordinates of all four corners of the rectangle.  The goal is to find the 3D coordinates of the unique point on the interior of the (3D, world) rectangle which projects to the given point.

(Do steps 1-3 below for both the 3D (world) coordinates, and the 2D (image) coordinates of the rectangle.)

Identify (any) one corner of the rectangle as its "origin", and call it "A", which we will treat as a vector.

Label the other vertices B, C, D, in order, so that C is diagonally opposite A.

Calculate the vectors v=AB and w=AD.  These form nice local coordinates for points in the rectangle.  Points in the rectangle will be of the form A+rv+sw, where r, s, are real numbers in the range [0,1].  This fact is true in world coordinates and in image coordinates.  In world coordinates, v and w are orthogonal, but in image coordinates, they are not.  That's ok.

Working in image coordinates, from the point (x,y) in the image of your rectangle, calculate the values of r and s.  This can be done by linear algebra on the vector equations (x,y) = A+rv+sw, where only r and s are unknown.  It will boil down to a 2x2 matrix equation, which you can solve generally in code using Cramer's rule.  (This step will break if the determinant of the required matrix is zero.  This corresponds to the case where the rectangle is seen edge-on.  The solution isn't unique in that case.  If that's possible, make special exception.)

Using the values of r and s from 4, compute A+rv+sw using the vectors A, v, w, for world coordinates.  That's the world point on the rectangle.

ContentLicense: CC BY-SA 2.5


问:
c #define macro string concatenation
Win7 SP1 32bit, Code Composer Studio v6.1 (I think they are using gcc)

I seem to be having some troubles getting the magic sequence to do the following...

I would like to write a preprocessor #define directive in the format:

(pseudo code)

```<code>#define extn(x) extern   uint16_t    str_#x
</code>```

then use it, thus:

```<code>extn(hello);
</code>```

then after preprocessing, have the result look like...

```<code>extern uint16_t  str_hello;
</code>```

This article in Wikipedia C preprocessor  states:

"You cannot combine a macro argument with additional text and stringify it all together. You can however write a series of adjacent string constants and stringified arguments: the C compiler will then combine all the adjacent string constants into one long string."

答:
What you want is concatenation rather than stringify. Hence, use ##:

```<code>#define extn(x) extern   uint16_t    str_##x
</code>```

ContentLicense: CC BY-SA 4.0

Title: c #define macro string concatenation

Body:
Win7 SP1 32bit, Code Composer Studio v6.1 (I think they are using gcc)

I seem to be having some troubles getting the magic sequence to do the following...

I would like to write a preprocessor #define directive in the format:

(pseudo code)

#define extn(x) extern   uint16_t    str_#x

then use it, thus:

extn(hello);

then after preprocessing, have the result look like...

extern uint16_t  str_hello;

This article in Wikipedia C preprocessor  states:

"You cannot combine a macro argument with additional text and stringify it all together. You can however write a series of adjacent string constants and stringified arguments: the C compiler will then combine all the adjacent string constants into one long string."

Body:
What you want is concatenation rather than stringify. Hence, use ##:

#define extn(x) extern   uint16_t    str_##x

ContentLicense: CC BY-SA 3.0


问:
meteor-jsdoc is not recognized as an internal or external command, operable program or batch file
I am trying to set up meteor-jsdoc on an existing meteor project according to the steps here:
https://www.npmjs.com/package/meteor-jsdoc

I am using windows and I run >npm install -g meteor-jsdoc , it is successfully

However when I try to run > meteor-jsdoc, it gives the error as in title.

I tried running the npm install both inside and outside the folder.

Anyone had the experience before? I am really stuck here.

Thanks!

答: Found the solution, re-installed git bash with unix tools option selected.</p>


问:
How can I compare two lists of numpy vectors?
I have two lists of numpy vectors and wish to determine whether they represent approximately the same points (but possibly in a different order).

I've found methods such as numpy.testing.assert_allclose but it doesn't allow for possibly different orders. I have also found unittest.TestCase.assertCountEqual but that doesn't work with numpy arrays!

What is my best approach?

```<code>import unittest

import numpy as np

first = [np.array([20, 40]), np.array([20, 60])]
second = [np.array([19.8, 59.7]), np.array([20.1, 40.5])]

np.testing.assert_all_close(first, second, atol=2)  # Fails because the orders are different
unittest.TestCase.assertCountEqual(None, first, second)  # Fails because numpy comparisons evaluate element-wise; and because it doesn't allow a tolerance
</code>```

答:
but possibly in a different order

This is the key requirement. This problem can be treat as a classic problem in graph theory - finding perfect matching in unweighted bipartite graph. Hungarian Algorithm is a classic algo to solve this problem.

Here I implemented one.

```<code>import numpy as np

def is_matched(first, second):
    checked = np.empty((len(first),), dtype=bool)
    first_matching = [-1] * len(first)
    second_matching = [-1] * len(second)

    def find(i):
        for j, point in enumerate(second):
            if np.allclose(first[i], point, atol=2):
                if not checked[j]:
                    checked[j] = True
                    if second_matching[j] == -1 or find(second_matching[j]):
                        second_matching[j] = i
                        first_matching[i] = j
                        return True

    def get_max_matching():
        count = 0
        for i in range(len(first)):
            if first_matching[i] == -1:
                checked.fill(False)
                if find(i):
                    count += 1

        return count

    return len(first) == len(second) and get_max_matching() == len(first)

first = [np.array([20, 40]), np.array([20, 60])]
second = [np.array([19.8, 59.7]), np.array([20.1, 40.5])]
print(is_matched(first, second))
# True

first = [np.array([20, 40]), np.array([20, 60])]
second = [np.array([19.8, 59.7]), np.array([20.1, 43.5])]
print(is_matched(first, second))
# False
</code>```

Body:
I have two lists of numpy vectors and wish to determine whether they represent approximately the same points (but possibly in a different order).

I've found methods such as numpy.testing.assert_allclose but it doesn't allow for possibly different orders. I have also found unittest.TestCase.assertCountEqual but that doesn't work with numpy arrays!

What is my best approach?

import unittest

import numpy as np

first = [np.array([20, 40]), np.array([20, 60])]
second = [np.array([19.8, 59.7]), np.array([20.1, 40.5])]

np.testing.assert_all_close(first, second, atol=2)  # Fails because the orders are different
unittest.TestCase.assertCountEqual(None, first, second)  # Fails because numpy comparisons evaluate element-wise; and because it doesn't allow a tolerance

Body:
but possibly in a different order

This is the key requirement. This problem can be treat as a classic problem in graph theory - finding perfect matching in unweighted bipartite graph. Hungarian Algorithm is a classic algo to solve this problem.

Here I implemented one.

import numpy as np

def is_matched(first, second):
    checked = np.empty((len(first),), dtype=bool)
    first_matching = [-1] * len(first)
    second_matching = [-1] * len(second)

    def find(i):
        for j, point in enumerate(second):
            if np.allclose(first[i], point, atol=2):
                if not checked[j]:
                    checked[j] = True
                    if second_matching[j] == -1 or find(second_matching[j]):
                        second_matching[j] = i
                        first_matching[i] = j
                        return True

    def get_max_matching():
        count = 0
        for i in range(len(first)):
            if first_matching[i] == -1:
                checked.fill(False)
                if find(i):
                    count += 1

        return count

    return len(first) == len(second) and get_max_matching() == len(first)

first = [np.array([20, 40]), np.array([20, 60])]
second = [np.array([19.8, 59.7]), np.array([20.1, 40.5])]
print(is_matched(first, second))
# True

first = [np.array([20, 40]), np.array([20, 60])]
second = [np.array([19.8, 59.7]), np.array([20.1, 43.5])]
print(is_matched(first, second))
# False


问:
How api calls are done with headers in swift
I want to securely provide my data from the API using JWT token.So Currently I have implemented security in the backend and each ajax call eith the header

```<code>url:"https://dataurl,
        contentType : "application/json; charset=utf-8",
        headers : TokenHeader(),
</code>```

But now I want to send the same data to be consumed by an IOS App which is developed in swift.I am not a IOS mobile developer and when I look into how they make the rest calls I found that something like this can be done:

```<code>let todosEndpoint: String = "https://dataurl"
guard let todosURL = URL(string: todosEndpoint) else {
  print("Error: cannot create URL")
  return
}
var todosUrlRequest = URLRequest(url: todosURL)
todosUrlRequest.httpMethod = "GET"
let newTodo: [String: Any] = ["title": "My First todo", "completed": false, "userId": 1]
let jsonTodo: Data
do {
  jsonTodo = try JSONSerialization.data(withJSONObject: newTodo, options: [])
  todosUrlRequest.httpBody = jsonTodo
} catch {
  print("Error: cannot create JSON from todo")
  return
}

let session = URLSession.shared

let task = session.dataTask(with: todosUrlRequest) {
  (data, response, error) in
  guard error == nil else {
    print("error calling POST on /todos/1")
    print(error)
    return
  }
  guard let responseData = data else {
    print("Error: did not receive data")
    return
  }
</code>```

So now my question is like ajax call in my web app how to consume rest service from the mobile app side.Any help is appreciated?

答:
You want something like (depending on what header values you need to send):</p>

```<code>todosUrlRequest.setValue("token value", forHTTPHeaderField: "Authorization")
</code>```

Body:
I want to securely provide my data from the API using JWT token.So Currently I have implemented security in the backend and each ajax call eith the header

url:"https://dataurl,
        contentType : "application/json; charset=utf-8",
        headers : TokenHeader(),

But now I want to send the same data to be consumed by an IOS App which is developed in swift.I am not a IOS mobile developer and when I look into how they make the rest calls I found that something like this can be done:

let todosEndpoint: String = "https://dataurl"
guard let todosURL = URL(string: todosEndpoint) else {
  print("Error: cannot create URL")
  return
}
var todosUrlRequest = URLRequest(url: todosURL)
todosUrlRequest.httpMethod = "GET"
let newTodo: [String: Any] = ["title": "My First todo", "completed": false, "userId": 1]
let jsonTodo: Data
do {
  jsonTodo = try JSONSerialization.data(withJSONObject: newTodo, options: [])
  todosUrlRequest.httpBody = jsonTodo
} catch {
  print("Error: cannot create JSON from todo")
  return
}

let session = URLSession.shared

let task = session.dataTask(with: todosUrlRequest) {
  (data, response, error) in
  guard error == nil else {
    print("error calling POST on /todos/1")
    print(error)
    return
  }
  guard let responseData = data else {
    print("Error: did not receive data")
    return
  }

So now my question is like ajax call in my web app how to consume rest service from the mobile app side.Any help is appreciated?

Body:
You want something like (depending on what header values you need to send):

todosUrlRequest.setValue("token value", forHTTPHeaderField: "Authorization")


问:
view to view in HMVC Code Igniter
i have some problem with hmvc in codeigniter because im newbie with hmvc.

i have a template bootstrap with ci  , so the problem like i not able to show my view

my view name index.php in directory "theme"  :

```<code><!DOCTYPE html>
<html lang="en">
<head>
    <?php echo $this->load->view('theme/header') ?>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
    <?php echo $this->load->view('theme/navbar') ?>
</nav>
<div id="wrapper">

    <div id="page-wrapper">
        <?php $this->load->view($content) ?>
    </div>

</div>
<?php echo $this->load->view('theme/footer') ?>
</body>
</code>```

My Controller name dashboard in directory "theme" :

```<code><?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Dashboard extends CI_Controller{

    function __construct()
    {
        parent::__construct();

    }
    function index()
    {
            $data['content'] = 'dashboard';
            return $this->load->view('theme/index', $data);
    }
}
</code>```

i the error is in  :

```<code><?php echo $this->load->view('theme/navbar') ?>
</code>```

and

```<code><?php echo $this->load->view('theme/footer') ?>
</code>```

the error Says :

"A PHP Error was encountered"

"Severity: 4096"

"Message:  Object of class MY_Loader could not be converted to string"

"Filename: theme/index.php"

"Line Number : 8"

Please help

答:
dont use echo

just $this->load->view('viewfile')

example if your view file is on application/view/theme/footer then it is

```<code>$this->load->view('theme/footer')
</code>```

if you want to convert it to string you can pass a boolean true in Third parameter
$this->load->view('theme/footer',array(),true)

Please refer to this codeigniter's view's documentation

Title: view to view in HMVC Code Igniter

Body:
i have some problem with hmvc in codeigniter because im newbie with hmvc.

i have a template bootstrap with ci  , so the problem like i not able to show my view

my view name index.php in directory "theme"  :

<!DOCTYPE html>

    <?php echo $this->load->view('theme/header') ?>

    <?php echo $this->load->view('theme/navbar') ?>

        <?php $this->load->view($content) ?>

<?php echo $this->load->view('theme/footer') ?>

My Controller name dashboard in directory "theme" :

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Dashboard extends CI_Controller{

    function __construct()
    {
        parent::__construct();

    }
    function index()
    {
            $data['content'] = 'dashboard';
            return $this->load->view('theme/index', $data);
    }
}

i the error is in  :

<?php echo $this->load->view('theme/navbar') ?>

and

<?php echo $this->load->view('theme/footer') ?>

the error Says :

"A PHP Error was encountered"

"Severity: 4096"

"Message:  Object of class MY_Loader could not be converted to string"

"Filename: theme/index.php"

"Line Number : 8"

Please help

Body:
dont use echo

just $this->load->view('viewfile')

example if your view file is on application/view/theme/footer then it is

$this->load->view('theme/footer')

if you want to convert it to string you can pass a boolean true in Third parameter
$this->load->view('theme/footer',array(),true)

Please refer to this codeigniter's view's documentation


问:
The Active Record will auto generate name
I study a e-book of Ruby on Rails:
If I create a Active Record below:

```<code>class Product < ApplicationRecord
end
</code>```

Rails Will execute the below code to generate a table:

```<code>CREATE TABLE products (
   id int(11) NOT NULL auto_increment,
   name varchar(255),
   PRIMARY KEY  (id)
);
</code>```

There I have a question, I can understand auto generate the major key, but why how to understand the:

```<code>name varchar(255),
</code>```

If the name field is auto generated? and if yes, why it is necessary?

答:
Yes, it will be auto generate. But it's not a activerecord action, it's related to the database. For mysql, if you doesn't set default value for the column, then it will default be NULL, nil in ruby.

Even you didn't set value for specific column, it also need to be display in the database, or visit as product.name, so do necessary.

Body:
I study a e-book of Ruby on Rails:
If I create a Active Record below:

class Product < ApplicationRecord
end

Rails Will execute the below code to generate a table:

CREATE TABLE products (
   id int(11) NOT NULL auto_increment,
   name varchar(255),
   PRIMARY KEY  (id)
);

There I have a question, I can understand auto generate the major key, but why how to understand the:

name varchar(255),

If the name field is auto generated? and if yes, why it is necessary?


问:
How to figure out the changeset a TFS 2015 build was build from?
I am distributing only binaries which were built by one of my TFS build definitions and each build receives a unique version number (1.0.$yy$dayofyear.$rev). The name of the build name contains this version number. The version number is set by a PowerShell script as the assembly version and the file version of the binary. I have only a build result rentention (including the built binaries in my drop folder) of 60 days and now I am wondering: How would I possibly figure out for some version number which is one year old which changeset it was built from so that I can have a look at the source code or rebuild exactly the binary? Do I have to add the changeset info somehow during my build explicitly? Do I have to encode the changeset number in my version number which is set during the build? Both ideas don't seem very ingenious.</p>

答:
You could add a powershell script or extension task which will generate release notes as part of TFS vNext build. You will get something as below:

And then you could store it, for the source code take a look at this blog


问:
Printing multiple lines with the same "largest" value using awk
I have a file that looks like this:

```<code>3, abc, x
2, def, y
3, ghi, z
</code>```

I want to find the highest value in $1 and print all rows that contain this highest value in $1.

```<code>sort -t, -k1,1n| tail -n1
</code>```

would just give one of the rows that contain 3 in $1, but I need both.

Any suggestions are appreciated (:

答:
Here is another approach that does not require sorting, but requires two passes over the data.</p>

```<code>max=$(awk -F',' '{if(max < $1) max = $1}END{print max}' Input.txt )
awk -v max=$max -F',' '$1 == max' Input.txt
</code>```

Body:
I have a file that looks like this:

3, abc, x
2, def, y
3, ghi, z

I want to find the highest value in $1 and print all rows that contain this highest value in $1.

sort -t, -k1,1n| tail -n1

would just give one of the rows that contain 3 in $1, but I need both.

Any suggestions are appreciated (:

Body:
Here is another approach that does not require sorting, but requires two passes over the data.

max=$(awk -F',' '{if(max < $1) max = $1}END{print max}' Input.txt )
awk -v max=$max -F',' '$1 == max' Input.txt


问:
float object over an image using CSS?
Is it possible to float an object over an image using css? I want to place a form over an image (that isn't a background). Float doesn't work, but is there some variable that does provide this function?

When you float an object it pushes the text to either side of the object. What I am looking for is something that will not do this, that will just float without regard to what is underneath it.

答:
What you are looking for is not what floating elements do. A floating element is still part of the document flow, and you want an element that isn't.

Use absolute positioning to take an element out of the document flow, that way it won't push other elements away and you can place it on top of other elements:

```<code><div style="position:relative">
  <img src="image.jpg" alt="" />
  <div style="position:absolute;left:0;top:0;">
    This text is on top of the image
  </div>
</div>
</code>```

The elements with position:relative acts as the origin for the absolutely positioned elements inside it, so that the text is placed on top of the image and not at the top left corner of the page.

Title: float object over an image using CSS?

Body:
What you are looking for is not what floating elements do. A floating element is still part of the document flow, and you want an element that isn't.

Use absolute positioning to take an element out of the document flow, that way it won't push other elements away and you can place it on top of other elements:

<div style="position:relative">
  <img src="image.jpg" alt="" />
  <div style="position:absolute;left:0;top:0;">
    This text is on top of the image
  </div>
</div>

The elements with position:relative acts as the origin for the absolutely positioned elements inside it, so that the text is placed on top of the image and not at the top left corner of the page.


问:
Android: Spinner setSelection by Tag
I define BaseAdapter to fill Spinner with records from SQL
I setTag for item in Spinner to equal Record ID in SQL database.

```<code>public static class Refueling_Adapter extends BaseAdapter {
    private Context vContext;
    private List<Banziny.Refuel> mRefuelingList;
    //private int mListing;

    public Base_Adapter(Context vContext, List<AppTest.basic> mBaseList) {
        this.vContext = vContext;
        this.mBaseList = mBaseList;
    }

    @Override
    public int getCount() {
        return mBaseList.size();
    }

    @Override
    public Object getItem(int position) {
        return mBaseList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

            convertView = View.inflate(vContext, R.layout.item_base, null);
            convertView.setTag(mBaseList.get(position).getBase_id());

            TextView Basename = (TextView) convertView.findViewById(R.id.txt_Base_name);
            Basename.setText(mBaseList.get(position).getBase_name());

        return convertView;
    }
}
</code>```

As you see I set Tag for spinner item to equal SQL record ID.
Now I just need to know how to setSelected for Spinner using Tag which equals SQL Record ID.

```<code>int baseidtoselect = mBaseList.get(0).getBase_ID();
</code>```

this id retrieved from database and i need to find tag in spinner.

答:
You can use this function</p>

```<code>public static void selectItemByTag(Spinner spinner, int tag) {
    Refueling_Adapter adapter = (Refueling_Adapter) spinner.getAdapter(); // it is Refueling_Adapter because your Spinner use Refueling_Adapter
    for (int position = 0; position < adapter.getCount(); position++) {
        if(((YourObjectModel)adapter.getItem(position)).getBase_id() == tag) { // YourObjectModel here is AppTest.basic
            spinner.setSelection(position);
            return;
        }
    }
}
</code>```

Title: Android: Spinner setSelection by Tag

Body:
I define BaseAdapter to fill Spinner with records from SQL
I setTag for item in Spinner to equal Record ID in SQL database.

public static class Refueling_Adapter extends BaseAdapter {
    private Context vContext;
    private List<Banziny.Refuel> mRefuelingList;
    //private int mListing;

    public Base_Adapter(Context vContext, List<AppTest.basic> mBaseList) {
        this.vContext = vContext;
        this.mBaseList = mBaseList;
    }

    @Override
    public int getCount() {
        return mBaseList.size();
    }

    @Override
    public Object getItem(int position) {
        return mBaseList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

            convertView = View.inflate(vContext, R.layout.item_base, null);
            convertView.setTag(mBaseList.get(position).getBase_id());

            TextView Basename = (TextView) convertView.findViewById(R.id.txt_Base_name);
            Basename.setText(mBaseList.get(position).getBase_name());

        return convertView;
    }
}

As you see I set Tag for spinner item to equal SQL record ID.
Now I just need to know how to setSelected for Spinner using Tag which equals SQL Record ID.

int baseidtoselect = mBaseList.get(0).getBase_ID();

this id retrieved from database and i need to find tag in spinner.

Body:
You can use this function

public static void selectItemByTag(Spinner spinner, int tag) {
    Refueling_Adapter adapter = (Refueling_Adapter) spinner.getAdapter(); // it is Refueling_Adapter because your Spinner use Refueling_Adapter
    for (int position = 0; position < adapter.getCount(); position++) {
        if(((YourObjectModel)adapter.getItem(position)).getBase_id() == tag) { // YourObjectModel here is AppTest.basic
            spinner.setSelection(position);
            return;
        }
    }
}


问:
UDP Server/Client for Game
I am trying to put together a tank game and I am having issues with the networking part. What am I doing wrong on the server??

Here is my server code :

```<code>import java.io.*;
import java.net.*;

class UDPServer extends Thread{
    private DatagramSocket socket;
    private TanksComponent tank;
    private InetAddress IPAddress;
    private int port = 9876;

    public void UPDServer() throws IOException{
        socket = new DatagramSocket(port);
    }

    public void run(){
        while(true){
            byte[] data = new byte[1024];
            DatagramPacket packet = new DatagramPacket(data, data.length);
            try {
                socket.receive(packet);
            } catch (IOException e) {
                e.printStackTrace();
            }
            System.out.println("RECEIVED: " + packet.getAddress() + " " + packet.getPort() + ": " + new String(packet.getData()) ) ;
            IPAddress = packet.getAddress();
        }
    }
    public void sendData(byte[] data){
        DatagramPacket packet = new DatagramPacket(data, data.length, IPAddress, port);
        try {
            this.socket.send(packet);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
</code>```

Here is my client code :

```<code>import java.io.*;
import java.net.*;

class UDPClient extends Thread{
    private InetAddress ipAddress;
    private DatagramSocket clientSocket;
    private TanksComponent tank;
    private byte[] data = new byte[1024];
    private int port = 9876;

    public UDPClient(TanksComponent tanksComponent) throws SocketException, UnknownHostException{
        this.tank = tanksComponent;
        this.clientSocket = new DatagramSocket();
        this.ipAddress = InetAddress.getLocalHost();
    }
    public void run(){

        DatagramPacket packet = new DatagramPacket(data, data.length);
        try {
            clientSocket.receive(packet);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();

        }
        String message = new String(packet.getData());
        System.out.println("SERVER > " + message);
    }
    public void sendData(byte[] data){
        DatagramPacket packet = new DatagramPacket(data, data.length, ipAddress, port);
        try {
            clientSocket.send(packet);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
</code>```

I am invoking the code like this :

```<code> public void start() throws UnknownHostException, SocketException {
      if(JOptionPane.showConfirmDialog(this, "Server") == 0){
            socketServer = new UDPServer();
            socketServer.start();

  }else{
      socketClient = new UDPClient(this);
      socketClient.start();
      System.out.println("Send");
      socketClient.sendData("ping".getBytes());
  }
</code>```

Thanks for the help kind stranger !

答:
I don't have a ton of experience with Java networking but feel free to look at a project I've been working on recently:

server

client

Title: UDP Server/Client for Game

Body:
I am trying to put together a tank game and I am having issues with the networking part. What am I doing wrong on the server??

Here is my server code :

import java.io.*;
import java.net.*;

class UDPServer extends Thread{
    private DatagramSocket socket;
    private TanksComponent tank;
    private InetAddress IPAddress;
    private int port = 9876;

    public void UPDServer() throws IOException{
        socket = new DatagramSocket(port);
    }

    public void run(){
        while(true){
            byte[] data = new byte[1024];
            DatagramPacket packet = new DatagramPacket(data, data.length);
            try {
                socket.receive(packet);
            } catch (IOException e) {
                e.printStackTrace();
            }
            System.out.println("RECEIVED: " + packet.getAddress() + " " + packet.getPort() + ": " + new String(packet.getData()) ) ;
            IPAddress = packet.getAddress();
        }
    }
    public void sendData(byte[] data){
        DatagramPacket packet = new DatagramPacket(data, data.length, IPAddress, port);
        try {
            this.socket.send(packet);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Here is my client code :

import java.io.*;
import java.net.*;

class UDPClient extends Thread{
    private InetAddress ipAddress;
    private DatagramSocket clientSocket;
    private TanksComponent tank;
    private byte[] data = new byte[1024];
    private int port = 9876;

    public UDPClient(TanksComponent tanksComponent) throws SocketException, UnknownHostException{
        this.tank = tanksComponent;
        this.clientSocket = new DatagramSocket();
        this.ipAddress = InetAddress.getLocalHost();
    }
    public void run(){

        DatagramPacket packet = new DatagramPacket(data, data.length);
        try {
            clientSocket.receive(packet);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();

        }
        String message = new String(packet.getData());
        System.out.println("SERVER > " + message);
    }
    public void sendData(byte[] data){
        DatagramPacket packet = new DatagramPacket(data, data.length, ipAddress, port);
        try {
            clientSocket.send(packet);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

I am invoking the code like this :

 public void start() throws UnknownHostException, SocketException {
      if(JOptionPane.showConfirmDialog(this, "Server") == 0){
            socketServer = new UDPServer();
            socketServer.start();

  }else{
      socketClient = new UDPClient(this);
      socketClient.start();
      System.out.println("Send");
      socketClient.sendData("ping".getBytes());
  }

Thanks for the help kind stranger !


问:
Scala - Return Map from a function in scala
```<code>Scala Code:-
import scala.io.Source

object Stocks1 {

  val filename = "stocks.csv"

  def main(args: Array[String]): Unit = {
    readStocks(filename)
  }

  def readStocks(fn: String): Map[String, Float] = {
//def readStocks(fn: String): Unit = {
    def percentChange(observed: Float, expected: Float): Float = {
      if (observed == 0 && expected == 0)
        0.0f
      else
        ((observed - expected) * 100) / expected
    }

    for (line <- Source.fromFile(fn).getLines()) {
      val list1 = line.split(",").map(_.trim).toList
      //Assigning Map to a val so in order to return Map(String,Float)
      val stock_map=Map(list1(2)->percentChange(list1(5).toFloat,list1(6).toFloat))
      stock_map
    }
  }
</code>```

I have to return Map[String, Float] but i don't know how to do it. I am pretty new to scala. I tried assigning it to stock_map to
    Map(list1(2)->percentChange(list1(5).toFloat,list1(6).toFloat)) but I am getting error as Type MIsmatch. Expected "Map[String, Float]" found "Unit".

答:
Try the following.

```<code>(for {
  line <- io.Source.fromFile(fn).getLines()
  list1 = line.split(",").map(_.trim).toList
} yield list1(2)->percentChange(list1(5).toFloat,list1(6).toFloat)
).toMap
</code>```

Scala for comprehensions don't work the way for() loops do in other languages. Beginners might find it advantageous to avoid them until they've achieved a fair understanding of how they work.

With that in mind, this is what the for comprehension is doing, which might be a little easier to understand.

```<code>io.Source.fromFile(fn).getLines().map{ line =>
  val list1 = line.split(",").map(_.trim).toList
  list1(2) -> percentChange(list1(5).toFloat, list1(6).toFloat)
}.toMap
</code>```

Body:
Scala Code:-
import scala.io.Source

object Stocks1 {

  val filename = "stocks.csv"

  def main(args: Array[String]): Unit = {
    readStocks(filename)
  }

  def readStocks(fn: String): Map[String, Float] = {
//def readStocks(fn: String): Unit = {
    def percentChange(observed: Float, expected: Float): Float = {
      if (observed == 0 && expected == 0)
        0.0f
      else
        ((observed - expected) * 100) / expected
    }

    for (line <- Source.fromFile(fn).getLines()) {
      val list1 = line.split(",").map(_.trim).toList
      //Assigning Map to a val so in order to return Map(String,Float)
      val stock_map=Map(list1(2)->percentChange(list1(5).toFloat,list1(6).toFloat))
      stock_map
    }
  }

I have to return Map[String, Float] but i don't know how to do it. I am pretty new to scala. I tried assigning it to stock_map to
    Map(list1(2)->percentChange(list1(5).toFloat,list1(6).toFloat)) but I am getting error as Type MIsmatch. Expected "Map[String, Float]" found "Unit".

Body:
Try the following.

(for {
  line <- io.Source.fromFile(fn).getLines()
  list1 = line.split(",").map(_.trim).toList
} yield list1(2)->percentChange(list1(5).toFloat,list1(6).toFloat)
).toMap

Scala for comprehensions don't work the way for() loops do in other languages. Beginners might find it advantageous to avoid them until they've achieved a fair understanding of how they work.

With that in mind, this is what the for comprehension is doing, which might be a little easier to understand.

io.Source.fromFile(fn).getLines().map{ line =>
  val list1 = line.split(",").map(_.trim).toList
  list1(2) -> percentChange(list1(5).toFloat, list1(6).toFloat)
}.toMap


问:
Emoji symbol  in string.xml crashes app
I would like to integrate the emoji symbol  in my android app. Therefore I looked up the hex code for the utf-8 symbol and added the following to my string.xml file:

```<code><string name="thumbsup">Perfect <node>👍👍</node></string>
</code>```

This should result into Perfect . However, instead my app crashes when the call activity tries to display this:

```<code>JNI DETECTED ERROR IN APPLICATION: input is not valid Modified UTF-8: illegal start byte 0xf0
</code>```

Not particularly perfect ;)

答:
It seems that newer versions of Android don't cause the crash (API 24 worked in my tests), but that doesn't help if you are supporting older versions. The best I have been able to figure out is to use Java coded strings.

```<code>public class AppEmojiStrings {

    // This is only a workaround for emoji causing crashes in XML strings.
    // Use the standard strings.xml for all other strings.

    public static final String thumbsUp = "Thumbs up ";
    public static final String iLoveNY = "I \uD83D\uDC99 NY";
}
</code>```

There are a number of disadvantages with this method, the main one being that it can't be accessed in the layout XML files. But it may be a viable workaround for some situations.

Title: Emoji symbol  in string.xml crashes app

Body:
I would like to integrate the emoji symbol  in my android app. Therefore I looked up the hex code for the utf-8 symbol and added the following to my string.xml file:

<string name="thumbsup">Perfect <node>👍👍</node></string>

This should result into Perfect . However, instead my app crashes when the call activity tries to display this:

JNI DETECTED ERROR IN APPLICATION: input is not valid Modified UTF-8: illegal start byte 0xf0

Not particularly perfect ;)

Body:
It seems that newer versions of Android don't cause the crash (API 24 worked in my tests), but that doesn't help if you are supporting older versions. The best I have been able to figure out is to use Java coded strings.

public class AppEmojiStrings {

    // This is only a workaround for emoji causing crashes in XML strings.
    // Use the standard strings.xml for all other strings.

    public static final String thumbsUp = "Thumbs up ";
    public static final String iLoveNY = "I \uD83D\uDC99 NY";
}

There are a number of disadvantages with this method, the main one being that it can't be accessed in the layout XML files. But it may be a viable workaround for some situations.


问:
How to remove dependency on System.Web.Mvc within domain model assembly containing POCOs
I have an assembly generated using POCO template using Entity Framework (e.g. "Company.Models.dll").Besides generated POCOs I also have "follow up" partial classes that define meta data using System.ComponentModel.DataAnnotations.
So for example Company.Models.Customer is auto-generated (in separate folder) and then I have partial class with same namespace. Within this partial class I define inner class for metadata...For example:

```<code>using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace Company.Models
{
    [MetadataType(typeof (CustomerMetaData))]
    public partial class Customer
    {
        public override string ToString()
        {
            return String.Format("Id: {0}, Name: {1}", Id, Name);
        }

        //[Bind(Exclude = "Id")]
        public class CustomerMetaData
        {
            [ScaffoldColumn(false)]
            public int Id { get; set; }

            [DisplayName("Name")]
            [Required(ErrorMessage = "Customer Name is required.")]
            [StringLength(100, ErrorMessage = "Customer name cannot exceed 100 characters.", MinimumLength = 2)]
            public string Name { get; set; }
        }
    }
}
</code>```

The issue I am having is that I now want to use this assembly in my MVC project and want to use MVC specific attributes (like the commented out Bind attribute above).However, doing so requires making my Company.Models.dll dependent on System.Web.Mvc.dll.

I would like to avoid this at all costs if possible but how?

So far I am aware of 2 possible solutions and am asking community for their opinions or better approaches...

Solution 1

This solution has been discussed here: Using Data Annotations on POCO's with MVC for Remote Validation The "trick" was to use ViewModels and map (either mannually or using AutoMapper) POCOs to MVC project specific ViewModels. Then apply all necessary attributes to ViewModels instead of domain model POCOs. While this makes sense for large projects it is a bit overkill for small simple solutions...

Solution 2

Use Bind attribute in Controller action parameters (as seen on some http://www.asp.net/mvc tutorials). For example:

```<code>//
// POST: /Customer/Create
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create([Bind(Exclude="Id")]Customer customerToCreate)
{
        if (!ModelState.IsValid)
        return View();

        // TODO: Add insert logic here
    return RedirectToAction("Index");
    }
</code>```

Using this solution would allow to skip dependency on System.Web.Mvc from my POCO dll at the cost of having to remember to insert Bind attribute on all relevant Controller actions.
Also, if I have multiple ASP.NET MVC projects the issue gets worse...

So, is there another way? ;)

答: <s>Easiest solution: put your Partial Class Customer in your MVC project. No other changes needed.</s>

Body:
I have an assembly generated using POCO template using Entity Framework (e.g. "Company.Models.dll").Besides generated POCOs I also have "follow up" partial classes that define meta data using System.ComponentModel.DataAnnotations.
So for example Company.Models.Customer is auto-generated (in separate folder) and then I have partial class with same namespace. Within this partial class I define inner class for metadata...For example:

using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace Company.Models
{
    [MetadataType(typeof (CustomerMetaData))]
    public partial class Customer
    {
        public override string ToString()
        {
            return String.Format("Id: {0}, Name: {1}", Id, Name);
        }

        //[Bind(Exclude = "Id")]
        public class CustomerMetaData
        {
            [ScaffoldColumn(false)]
            public int Id { get; set; }

            [DisplayName("Name")]
            [Required(ErrorMessage = "Customer Name is required.")]
            [StringLength(100, ErrorMessage = "Customer name cannot exceed 100 characters.", MinimumLength = 2)]
            public string Name { get; set; }
        }
    }
}

The issue I am having is that I now want to use this assembly in my MVC project and want to use MVC specific attributes (like the commented out Bind attribute above).However, doing so requires making my Company.Models.dll dependent on System.Web.Mvc.dll.

I would like to avoid this at all costs if possible but how?

So far I am aware of 2 possible solutions and am asking community for their opinions or better approaches...

Solution 1

This solution has been discussed here: Using Data Annotations on POCO's with MVC for Remote Validation The "trick" was to use ViewModels and map (either mannually or using AutoMapper) POCOs to MVC project specific ViewModels. Then apply all necessary attributes to ViewModels instead of domain model POCOs. While this makes sense for large projects it is a bit overkill for small simple solutions...

Solution 2

Use Bind attribute in Controller action parameters (as seen on some http://www.asp.net/mvc tutorials). For example:

//
// POST: /Customer/Create
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create([Bind(Exclude="Id")]Customer customerToCreate)
{
        if (!ModelState.IsValid)
        return View();

        // TODO: Add insert logic here
    return RedirectToAction("Index");
    }

Using this solution would allow to skip dependency on System.Web.Mvc from my POCO dll at the cost of having to remember to insert Bind attribute on all relevant Controller actions.
Also, if I have multiple ASP.NET MVC projects the issue gets worse...

So, is there another way? ;)


问:
Bootstrap 4 Modal Will Not Open on Click
I can not get my modal to open. I tried just the plain HTML found on the Bootstrap 4 site and then used some Javascript. I really can not figure out what I am doing wrong. Any help would be very much appreciated!

enter code here<

```<code><div class="col-sm-3 col-centered  boxes" id="box1">

  <button type="button" class="btn btn-primary" id="box1modal" data-toggle="modal" data-target="#exampleModal">

    See More

  </button>

  <!-- Modal -->
  <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">

    <div class="modal-dialog" role="document">

      <div class="modal-content">

        <div class="modal-header">

          <h5 class="modal-title" id="exampleModalLabel">Wedding Invites</h5>

          <button type="button" class="close" data-dismiss="modal" aria-label="Close">

            <span aria-hidden="true">×</span>

          </button>

        </div>

        <div class="modal-body">

          <img src="Wedding%20Invites.jpg">

        </div>

        <div class="modal-footer">

          <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>

          <button type="button" class="btn btn-primary">Save changes</button>

        </div>

      </div>

    </div>

  </div>

</div>
 `enter code here`<script type="text/javascript">
</code>```

enter code here $("#box1modal").click(function(event){

 enter code here$('#myModal').modal('show');
    enter code here  )};

答: You have given the data target as examplemodal and the id of div as mymodal. Both should have been the same, thats the issue.</p>

Body:
I can not get my modal to open. I tried just the plain HTML found on the Bootstrap 4 site and then used some Javascript. I really can not figure out what I am doing wrong. Any help would be very much appreciated!

enter code here<

  <button type="button" class="btn btn-primary" id="box1modal" data-toggle="modal" data-target="#exampleModal">

    See More

  </button>

Wedding Invites

          <button type="button" class="close" data-dismiss="modal" aria-label="Close">

            ×

          </button>

          <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>

          <button type="button" class="btn btn-primary">Save changes</button>

 `enter code here`


问:
Azure servicebus messages when webapp scale out to fewer instances
What happens if you have let's say 4 instances of a webapp, and a lot of messages queued up in the service bus queue (meant to reach all the 4 instances) and the webapp scales down to only 2 instances. Will the messages, in the service bus that were meant for the other two instances that were removed, be stuck in the queue until the time to live is exceeded and then removed or does the service bus understand that there are not 4 instances anymore and therefore it doesn't need to send out messages to 4 instances?

I'm not sure if this is the correct but from my understanding there usually is a topic and then multiple subscriptions? will the service bus understand when one of the instances (who has a subscription) is gone and then removes the message meant for that subscription while the message is queued up (a lot of other messages before it)?

Sorry if the question is a little dumb but I couldn't find any answers on the internet.

答:
Will the messages, in the service bus that were meant for the other two instances that were removed, be stuck in the queue until the time to live is exceeded and then removed

Service Bus queues and topic subscriptions provide a secondary sub-queue, called a dead-letter queue (DLQ).
The purpose of the dead-letter queue is to hold messages that cannot be delivered to any receiver, or simply messages that could not be processed. More details please refer to the document.

does the service bus understand that there are not 4 instances anymore and therefore it doesn't need to send out messages to 4 instances?

Service Bus Queues offer First In, First Out (FIFO) message and Service Bus queue  message is received and processed by only one message consumer. If we have multiple  web instance, when a quest arrive then WebApp LoadBlance (ARR) will assign  the request to the corresponding instance to process the message. If the instance has been removed, the WebApp loadBlance (ARR) will assign the request to the existing instance.

will the service bus understand when one of the instances (who has a subscription) is gone and then removes the message meant for that subscription while the message is queued up (a lot of other messages before it)?

As mentioned above, it is assigned by WebApp LoadBlance not Service bus. How to consume message is depended on your WebApp.


问:
ScrollView won't scroll, just cuts off the screen. How to fix?
I know this question has been asked, but I haven't found anything that works. Here's my xml:

```<code><?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.project.myproject.SpendFragment">

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="@string/testBannerAdId">
    </com.google.android.gms.ads.AdView>

    <ScrollView
        android:layout_above="@id/adView"
        android:padding="@dimen/layoutPadding"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <LinearLayout
                android:weightSum="100"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageButton
                    android:id="@+id/alabamaButton"
                    android:contentDescription="Alabama"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"/>

                <ImageButton
                    android:id="@+id/alaskaButton"
                    android:contentDescription="Alaska"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"/>

                <ImageButton
                    android:id="@+id/arizonaButton"
                    android:contentDescription="Arizona"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/arkansasButton"
                    android:contentDescription="Arkansas"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

            </LinearLayout>

            <LinearLayout
                android:weightSum="100"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageButton
                    android:id="@+id/californiaButton"
                    android:text="California"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/coloradoButton"
                    android:text="Colorado"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/connecticutButton"
                    android:text="Connecticut"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/delawareButton"
                    android:text="Delaware"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

            </LinearLayout>

            <LinearLayout
                android:weightSum="100"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageButton
                    android:id="@+id/floridaButton"
                    android:text="Florida"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/georgiaButton"
                    android:text="Georgia"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/hawaiiButton"
                    android:text="Hawaii"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/idahoButton"
                    android:text="Idaho"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

            </LinearLayout>

            <LinearLayout
                android:weightSum="100"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageButton
                    android:id="@+id/illinoisButton"
                    android:text="Illinois"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/indianaButton"
                    android:text="Indiana"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/iowaButton"
                    android:text="Iowa"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/kansasButton"
                    android:text="Kansas"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

            </LinearLayout>

            <LinearLayout
                android:weightSum="100"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageButton
                    android:id="@+id/kentuckyButton"
                    android:text="Kentucky"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/louisianaButton"
                    android:text="Louisiana"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/maineButton"
                    android:text="Maine"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/marylandButton"
                    android:text="Maryland"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

            </LinearLayout>

            <LinearLayout
                android:weightSum="100"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageButton
                    android:id="@+id/massachusettsButton"
                    android:text="Massachusetts"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/michiganButton"
                    android:text="Michigan"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/minnesotaButton"
                    android:text="Minnesota"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/mississippiButton"
                    android:text="Mississippi"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

            </LinearLayout>

            <LinearLayout
                android:weightSum="100"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageButton
                    android:id="@+id/missouriButton"
                    android:text="Missouri"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/montanaButton"
                    android:text="Montana"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/nebraskaButton"
                    android:text="Nebraska"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/nevadaButton"
                    android:text="Nevada"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

            </LinearLayout>
        </LinearLayout>

    </ScrollView>

</RelativeLayout>
</code>```

In case it's relevant, here's the xml for the Main activity that the fragment's in:

```<code><android.support.design.internal.ScrimInsetsFrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent"
    android:fitsSystemWindows="true"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    tools:context="com.project.myproject.MainActivity" >

    <FrameLayout
        android:id="@+id/frameLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </FrameLayout>

    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawerLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.NavigationView
            android:id="@+id/navigationView"
            android:layout_gravity="start"
            android:layout_width="@dimen/drawerWidth"
            android:layout_height="@dimen/drawerHeight"
            app:menu="@menu/drawer_menu" />

    </android.support.v4.widget.DrawerLayout>

</android.support.design.internal.ScrimInsetsFrameLayout>
</code>```

There are more LinearLayouts within the LinearLayout, but you get the idea (more ImageButtons of states). I can see the little scroll thing on the right once, but it disappears and doesn't come back up. And in case it's relevant, there's space for the AdView on the bottom but it's just white space. I know that happens sometimes with a real ad, so I just figure the little placeholder ad will show up eventually.

As you can see, my ScrollView's height is match_parent and my LinearLayout's height is wrap_content. I have one child in the ScrollView. The ScrollView is wrapped in a RelativeLayout only because I want the AdView to be under the ScrollView. Is the issue is that there are multiple children in the outer LinearLayout? I've never had any issues with ScrollViews before so this is a little annoying haha.

Thank you!

EDIT: Here are two images. The only difference is that one has the little scrollbar on the side and the other doesn't. It disappears and never reappears on touch or movement. The blue squares are the placeholder images and there are four squares per inner LinearLayout.

答:
width and height of ScrollView cannot both be "match_parent".

You can try change the height of ScrollView to "wrap_content" to see if it's work.

Body:
I know this question has been asked, but I haven't found anything that works. Here's my xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.project.myproject.SpendFragment">

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="@string/testBannerAdId">
    </com.google.android.gms.ads.AdView>

    <ScrollView
        android:layout_above="@id/adView"
        android:padding="@dimen/layoutPadding"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <LinearLayout
                android:weightSum="100"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageButton
                    android:id="@+id/alabamaButton"
                    android:contentDescription="Alabama"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"/>

                <ImageButton
                    android:id="@+id/alaskaButton"
                    android:contentDescription="Alaska"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"/>

                <ImageButton
                    android:id="@+id/arizonaButton"
                    android:contentDescription="Arizona"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/arkansasButton"
                    android:contentDescription="Arkansas"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

            </LinearLayout>

            <LinearLayout
                android:weightSum="100"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageButton
                    android:id="@+id/californiaButton"
                    android:text="California"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/coloradoButton"
                    android:text="Colorado"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/connecticutButton"
                    android:text="Connecticut"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/delawareButton"
                    android:text="Delaware"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

            </LinearLayout>

            <LinearLayout
                android:weightSum="100"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageButton
                    android:id="@+id/floridaButton"
                    android:text="Florida"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/georgiaButton"
                    android:text="Georgia"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/hawaiiButton"
                    android:text="Hawaii"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/idahoButton"
                    android:text="Idaho"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

            </LinearLayout>

            <LinearLayout
                android:weightSum="100"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageButton
                    android:id="@+id/illinoisButton"
                    android:text="Illinois"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/indianaButton"
                    android:text="Indiana"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/iowaButton"
                    android:text="Iowa"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/kansasButton"
                    android:text="Kansas"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

            </LinearLayout>

            <LinearLayout
                android:weightSum="100"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageButton
                    android:id="@+id/kentuckyButton"
                    android:text="Kentucky"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/louisianaButton"
                    android:text="Louisiana"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/maineButton"
                    android:text="Maine"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/marylandButton"
                    android:text="Maryland"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

            </LinearLayout>

            <LinearLayout
                android:weightSum="100"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageButton
                    android:id="@+id/massachusettsButton"
                    android:text="Massachusetts"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/michiganButton"
                    android:text="Michigan"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/minnesotaButton"
                    android:text="Minnesota"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/mississippiButton"
                    android:text="Mississippi"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

            </LinearLayout>

            <LinearLayout
                android:weightSum="100"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageButton
                    android:id="@+id/missouriButton"
                    android:text="Missouri"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/montanaButton"
                    android:text="Montana"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/nebraskaButton"
                    android:text="Nebraska"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/nevadaButton"
                    android:text="Nevada"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

            </LinearLayout>
        </LinearLayout>

    </ScrollView>

</RelativeLayout>

In case it's relevant, here's the xml for the Main activity that the fragment's in:

<android.support.design.internal.ScrimInsetsFrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent"
    android:fitsSystemWindows="true"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    tools:context="com.project.myproject.MainActivity" >

    <FrameLayout
        android:id="@+id/frameLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </FrameLayout>

    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawerLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.NavigationView
            android:id="@+id/navigationView"
            android:layout_gravity="start"
            android:layout_width="@dimen/drawerWidth"
            android:layout_height="@dimen/drawerHeight"
            app:menu="@menu/drawer_menu" />

    </android.support.v4.widget.DrawerLayout>

</android.support.design.internal.ScrimInsetsFrameLayout>

There are more LinearLayouts within the LinearLayout, but you get the idea (more ImageButtons of states). I can see the little scroll thing on the right once, but it disappears and doesn't come back up. And in case it's relevant, there's space for the AdView on the bottom but it's just white space. I know that happens sometimes with a real ad, so I just figure the little placeholder ad will show up eventually.

As you can see, my ScrollView's height is match_parent and my LinearLayout's height is wrap_content. I have one child in the ScrollView. The ScrollView is wrapped in a RelativeLayout only because I want the AdView to be under the ScrollView. Is the issue is that there are multiple children in the outer LinearLayout? I've never had any issues with ScrollViews before so this is a little annoying haha.

Thank you!

EDIT: Here are two images. The only difference is that one has the little scrollbar on the side and the other doesn't. It disappears and never reappears on touch or movement. The blue squares are the placeholder images and there are four squares per inner LinearLayout.