The image of the network with Glide too small on Android
source link: https://www.codesd.com/item/the-image-of-the-network-with-glide-too-small-on-android.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
The image of the network with Glide too small on Android
I am trying to download an image from the network and display in the ImageView with Glide using scaleType="centerInside" option.
For some reason, the image, when downloaded from the network, looks much smaller on the screen than when the same image is put into the ImageView from resources.
Example:
Both images can be found here. I would argue that even those images that have been set from resources look smaller than they could actually be when compared to what I see on my laptop. I understand that there is something related to the screen density in play, but how can I make these images be of "user-friendly size", e.g., a bit larger?
Even a different image of 600x250 px size is ridiculously small on the phone (with ImageView's layout_height and layout_width set to "wrap_content").
Code from the Activity:
public class DisplayImagesActivity extends AppCompatActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.display_image_activity);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
setTitle("Hello StackOverflow!");
ImageView top_left = (ImageView) findViewById(R.id.top_left);
ImageView top_right = (ImageView) findViewById(R.id.top_right);
ImageView bottom_left = (ImageView) findViewById(R.id.bottom_left);
ImageView bottom_right = (ImageView) findViewById(R.id.bottom_right);
String[] urls = new String[] {
"http://imgur.com/6jMOdg0.png",
"http://imgur.com/AhIziYr.png"
};
top_left.setImageResource(R.drawable.top_left);
top_right.setImageResource(R.drawable.top_right);
Glide.with(this)
.load(urls[0])
.signature(new StringSignature(new Date().toString()))
.into(bottom_left);
Glide.with(this)
.load(urls[1])
.signature(new StringSignature(new Date().toString()))
.into(bottom_right);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
this.finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
display_image_activity.xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/match_parent"
android:orientation="vertical">
<include layout="@layout/_toolbar" />
<ScrollView
style="@style/match_parent">
<RelativeLayout
style="@style/match_parent"
android:padding="16dp">
<TextView
style="@style/wrap_content"
android:id="@+id/text_resources"
android:layout_marginBottom="10dp"
android:text="From Resources"/>
<ImageView
android:id="@+id/top_left"
android:background="@color/Linen"
android:layout_width="150dp"
android:layout_height="120dp"
android:layout_marginBottom="20dp"
android:layout_below="@id/text_resources"
android:scaleType="centerInside"/>
<ImageView
android:id="@+id/top_right"
android:background="@color/Linen"
android:layout_width="150dp"
android:layout_height="120dp"
android:layout_toRightOf="@id/top_left"
android:layout_toEndOf="@id/top_left"
android:layout_below="@id/text_resources"
android:layout_marginLeft="20dp"
android:layout_marginStart="20dp"
android:scaleType="centerInside"/>
<TextView
style="@style/wrap_content"
android:id="@+id/text_network"
android:layout_below="@id/top_left"
android:layout_marginBottom="10dp"
android:text="From Network"/>
<ImageView
android:id="@+id/bottom_left"
android:background="@color/Linen"
android:layout_width="150dp"
android:layout_height="120dp"
android:layout_below="@id/text_network"
android:scaleType="centerInside" />
<ImageView
android:id="@+id/bottom_right"
android:background="@color/Linen"
android:layout_width="150dp"
android:layout_height="120dp"
android:layout_toRightOf="@id/bottom_left"
android:layout_toEndOf="@id/bottom_left"
android:layout_below="@id/text_network"
android:layout_marginLeft="20dp"
android:layout_marginStart="20dp"
android:scaleType="centerInside" />
</RelativeLayout>
</ScrollView>
</LinearLayout>
Thank you.
Your images cannot be bigger than what you defined:
android:layout_width="150dp"
android:layout_height="120dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK