【问题标题】:ScrollView is working in android studio but not on my smartphoneScrollView 在 android studio 中工作,但不在我的智能手机上
【发布时间】:2017-06-24 14:34:26
【问题描述】:

我不知道为什么它在 IDE 中工作,但是当我在我的设备上安装 apk 时。 (我在 RelativeLayout 中有一个 4000x1080 像素的背景图像)。

android:id="@+id/scrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#f7f7f7"
android:fillViewport="true"
android:orientation="vertical">

<RelativeLayout 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="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="@mipmap/space1"
    android:fillViewport="true"
    android:padding="0dp">

    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="56dp"
        android:text="Hello World !"
        android:textColor="#FFFFFF"/>

    <ImageButton
        android:id="@+id/imageButton"
        android:layout_width="55dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:background="@null"
        android:padding="5dp"
        android:scaleType="centerInside"
        app:srcCompat="@drawable/level1"
        android:gravity="center"
        android:layout_marginLeft="455px"
        android:layout_marginTop="1300px"/>


</RelativeLayout>

提前感谢您的帮助。

【问题讨论】:

  • 我认为问题在于我的布局包含在另一个布局中,因此 onClickListener 无法捕获 ImageView 的 id...实际上是这种情况:父级包含包含 myLayout 和 ImageView 的 child1。 .
  • 我在java类中试过这个,但是id不起作用:ImageButton level1 = (ImageButton) findViewById(R.id.father).findViewById(R.id.child).findViewById(R .id.imageView) ;我能做什么?

标签: android xml scrollview


【解决方案1】:

尝试将大图像放在相对布局内的 ImageView 中,而不是作为背景...最好使用 dp 尺寸单位而不是 px

【讨论】:

    【解决方案2】:

    只需添加 ScrollView 并从 RelativeLayout 中删除

    <...
    
    android:fillViewport="true"
    
     .../>
    

    【讨论】:

      猜你喜欢
      • 2016-10-17
      • 1970-01-01
      • 2018-09-15
      • 2019-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-28
      • 2019-12-13
      相关资源
      最近更新 更多