【问题标题】:how to make full width and height imageView with admob displayed?如何使用 admob 显示全宽和全高 imageView?
【发布时间】:2018-09-11 08:11:36
【问题描述】:

我在图像视图中显示 Glide 图像时遇到问题。 我已经在这个很棒的网站上搜索了答案和其他网站,但没有达到目标!

1- 第一个问题:我想显示具有图像视图的全宽和全高的图像..

2- 第二个问题:如何制作全宽的可滚动图像视图...

请帮帮我!!我正在使用 GLIDE 库,并且我使用了许多其他库进行图像转换( BigImageView ..)

感谢您的帮助

这是 DisplayImg Activity 的代码

public class DisplayImg extends AppCompatActivity {

Context c ;
PhotoViewAttacher photoViewAttacher;
private AdView mAdView;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_display_img);



    ImageView imageView =  findViewById(R.id.imageView);

    GlideApp
            .with(this).load(R.drawable.display)
            .diskCacheStrategy(DiskCacheStrategy.NONE)
            .into(imageView);


    photoViewAttacher=new PhotoViewAttacher(imageView);



    // Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713
    MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713");
    mAdView = findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);









    // Making notification bar transparent
    if (Build.VERSION.SDK_INT >= 21) {
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
    }
    changeStatusBarColor();
}

private void changeStatusBarColor() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(Color.TRANSPARENT);
    }
}

}

布局代码:

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="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=".DisplayImg">

<com.github.chrisbanes.photoview.PhotoView
    android:id="@+id/imageView"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:src="@drawable/display"
    app:layout_constraintBottom_toTopOf="@+id/adView"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginEnd="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginStart="8dp"
    ads:adSize="BANNER"
    ads:adUnitId="ca-app-pub-3940256099942544/6300978111"
    ads:layout_constraintBottom_toBottomOf="parent"
    ads:layout_constraintEnd_toEndOf="parent"
    ads:layout_constraintStart_toStartOf="parent"></com.google.android.gms.ads.AdView>

This is the current now

【问题讨论】:

  • 贴出你到目前为止所做的代码
  • 谢谢,请看代码
  • 所以你的问题是如何使用屏幕的整个宽度和图像的可滚动高度?请也发布您的 xml。
  • 是的..正是..请看代码
  • 请立即检查代码!包括布局

标签: android android-layout android-studio android-glide


【解决方案1】:

像这样改变你的 xml 并告诉我这是否有效:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

<ScrollView
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1">

    <com.github.chrisbanes.photoview.PhotoView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/display"
        android:scaleType = "fitXY"/>

</ScrollView>

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|center">

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        ads:adSize="BANNER"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adUnitId="ca-app-pub-3940256099942544/6300978111" />

</LinearLayout>

</LinearLayout>

【讨论】:

  • 男人!你是天才!!谢谢兄弟
  • 它适用于手机!但在平板电脑上它不起作用!请帮忙
  • 我现在不在身边,所以无法使用 android studio,稍后我会回复您。此外,点赞是表达赞赏的真正方式;)
  • @Frankensteinleb 嘿抱歉我迟到了。我更新了代码,请立即检查。我在 nexus 7 和一加 3 中进行了测试,运行良好。
猜你喜欢
  • 1970-01-01
  • 2012-03-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-23
  • 1970-01-01
相关资源
最近更新 更多