How can I load photos of the Android app?

Source: Internet
Author: User

The saying goes that spring is like the face of B people, and it will take a while for rain. Suner is still in rainy days, so it is clear today. When the breeze blew in, listening to the peach blossom of A Niu Ge, I couldn't help but think of a Southern Song Dynasty high rich handsome about the gun slogan: "waist around 100,000, riding a crane under Yangzhou ". Think of this poor path for a while, "Should you be a kind of person, you want to soak in the whole Yangzhou City ?" Turning over your own wallet, although it is not enough to ride a crane to Yangzhou for only 10 yuan, but it is still possible to ride a bicycle to eat a bowl of porridge. Just as the poor man got up and prepared for dinner, he looked very cool, such as Uncle QA of Hua. He sang the school song and jumped all the way. If the last image was in a different position on the screen and its size was a miracle, this time it was a strange thing. The normal picture is displayed on the flat panel (see figure 1), and only the middle part of the picture is displayed on the Qa panel (see figure 2 ). At this moment, the poor Tao suddenly planted a moment, and zhenzi MM will crawl out of the screen. In order to detect the problem, the poor man braved the danger that the son MM would climb out and forcibly detained the Qa tablet.

Figure 1 Figure 2

The poor path quickly wrote a test code. Because the ImageView size is X pixels and the image is X pixels, the correct picture should be exactly displayed.

Activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context=".MainActivity" >    <ImageView        android:id="@+id/img"        android:layout_width="200px"        android:layout_height="200px"        android:layout_centerHorizontal="true"        android:layout_centerVertical="true"        android:scaleType="center"    /></RelativeLayout>

MainActivity. java

package com.example.testimg;import android.os.Bundle;import android.app.Activity;import android.view.Menu;import android.widget.ImageView;public class MainActivity extends Activity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);                ImageView imv = (ImageView)this.findViewById(R.id.img);         imv.setImageResource(R.drawable.emp);            }    @Override    public boolean onCreateOptionsMenu(Menu menu) {        // Inflate the menu; this adds items to the action bar if it is present.        getMenuInflater().inflate(R.menu.activity_main, menu);        return true;    }}

The test program is still normal on the poor tablet, and then runs on the Qa tablet. This article will always show "but" Jun, as you may come. Only a part of the image is displayed. Poor Dao looked at his own fake tablet and Qa's cool and cool Nexus 7. Is Android also engaged in brand discrimination. Noble ones do not look like fake cards? Isn't the hope country Where Android is located claim that everyone is equal? It seems that equality and inequality can only be seen by the poor. Of course, the country cannot go, but it is still possible to debug the program.

Since the image display is incomplete, it indicates that the ImageView control or the image size is incorrect. Therefore, the code for obtaining the ImageView and image size is added to the poor path.

MainActivity. java

protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);                                ImageView imv = (ImageView)this.findViewById(R.id.img);        int w1 = imv.getWidth();        int h1 = imv.getHeight();                Bitmap img = BitmapFactory.decodeResource(this.getResources(),R.drawable.emp);        int w2 = img.getWidth();        int h2 = img.getHeight();                imv.setImageBitmap(img);            }

After you press the debug button, the Width and Height of the image are changed to 266 instead of the size of the image (see figure 3 ). We hope that the country name will be equal, and the ugly face of the hegemony will no doubt appear again. At this time, the sky began to rain again, as if it was silly, on the card, the school was filled with tears.

Figure 3

Does it continue to expose its false equality black screen? When we think of the kingdom who has been armed with teeth, we can't help but fight the Cold War and think of shame. At this moment, the tumble voice of Taizu sounded in the mind of the poor road: "American imperialism is a paper tiger ". In the distance, there was a sense of mission in the poor path, and suddenly there was a figure in the Heman's Wei 'an, so I couldn't help holding the lightning rod in the window and shouted: "Chun Ge, give me strength. "In an instant, the poor road is shining like a cow, is it in progress? Naturally, the answer is no, but it is only a natural phenomenon of heat and light produced by electric currents passing through human flesh resistance. At the same time, a yellow note with the seal-writing characters slowly fell down, and I saw it: "android never asked Google, but the bell will be reached. "

When I saw this, I couldn't help but think of it. A few days ago I attended a Land and Water Big Law Conference sponsored by Google. At the conference, I happened to have a Taoist preaching about the Android UI layout. In the course of preaching, it was amazing to demonstrate that the layout of the interface is consistent under different resolutions, without the control size and position display being different due to resolution changes. When the poor man wants to ask the truth, this friend has posted the so-called handouts, and then has to fly up. In the eyes of everyone's envy, There is a dark line between the poor and the poor. Is it true that developing Android can also improve the experience. Looking at the handouts flying all over the sky, the poor man reached out and grabbed one. He only saw a few google URLs printed on the hard paper that wiped his ass. Poor road is very disdainfully inserted into the bag, it should be a draft paper.

Pull out the crumpled handout and click a link. As mentioned above, Android divides the tablet into four grades based on dpi to adapt the app to different tablet resolutions. Dpi, screen density is also. 1 inch 160 pixels are called the medium density screen, also known as the benchmark density screen (mdpi). ldpi is lower than this standard, hdpi is higher than this standard, and xhdpi is higher. At the same time, four peer directories (drawable-hdp, drawable-ldpi, drawable-mdpi, and drawable-xhdpi) are generated under the res directory as follows:

Xhdpi :~ 320 dpi

Hdpi :~ 240 dpi

Mdpi :~ 160 dpi

Ldpi :~ 120 dpi

At this time, the poor road suddenly realized that the poor road flat was originally a medium density screen in developing countries, while the QA Nexus 7 was already a high density screen, which had reached the level of developed countries. It seems that the US, which is known as the hope of mankind, is not only unequal, but also poor and rich. What's even worse, the program is looking for related resources from different directories Based on dpi. If it cannot be found in this directory, it will look for other directories. After the image is found, the size of the image is determined based on the dpi of the current screen/the dpi of the image directory. Taking this article as an example, the dpi of Nexus 7 is 208dpi which belongs to hdpi. If the image is only placed in drawable-mdpi, it is not put in drawable-hdpi. In this way, when the program runs on Nexus 7, the width and height of the image are 208/160 times that of the original image, that is, about 1.3 times. When I checked the test program, I only saved images in the drawable-mdpi directory, but not in the drawable-hdpi directory, this is why the width and height of the image are 266px, because they are magnified by 1.3 times.

We can see that this poor path is miserable. In the world of Android, high-end people operate freely with their resources, resulting in coefficient expansion and disaster occurrence. The poor path can't help but sigh, and the time for the peaceful world to return to the human world. At this time, the poor path falls into deep meditation.

 

<Previous article: Margin, a strange old story about Android 2 and 3

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.