2016-05-03 5 views
1

Как установить фоновое изображение для макета с помощью scroolview, потому что когда я добавляю ImageView в код ниже, scroolview начинает работать очень медленно. Изображение имеет 700kb. Если я установил android:background="@drawable/background04" в relativeLayout, scroolview также работает очень медленно.Медленная прокрутка с фоновым изображением

<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="com.example.scrollview.MainActivity"> 

<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:scaleType="centerCrop" 
    android:src="@drawable/background04" 
    android:alpha="0.8" 
    android:layout_centerHorizontal="true" /> 

<ScrollView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/scrollView" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentEnd="true" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" > 

    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentTop="true"> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="64dp" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:text="Large Text" 
      android:id="@+id/textView" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="64dp" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:text="Large Text" 
      android:id="@+id/textView2" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="64dp" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:text="Large Text" 
      android:id="@+id/textView3" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="64dp" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:text="Large Text" 
      android:id="@+id/textView4" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="64dp" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:text="Large Text" 
      android:id="@+id/textView5" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="64dp" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:text="Large Text" 
      android:id="@+id/textView6" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="64dp" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:text="Large Text" 
      android:id="@+id/textView7" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="64dp" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:text="Large Text" 
      android:id="@+id/textView8" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="64dp" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:text="Large Text" 
      android:id="@+id/textView9" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="64dp" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:text="Large Text" 
      android:id="@+id/textView10" /> 

    </LinearLayout> 

</ScrollView> 

Edit:

Для тестирования я использую HTC Desire 820.

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.aapps.scrollview"> 

<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 
    <activity android:name=".MainActivity"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
</application> 

Logcat:

05-03 10:48:04.750 17843-17891/com.aapps.scrollview E/OpenGLRenderer: CacheDebug: generateTexture() in TextureCache::get(, if (!texture): bitmap = 0x55a971acb0 
05-03 10:48:04.750 17843-17891/com.aapps.scrollview E/OpenGLRenderer: CacheDebug: generateTexture() in TextureCache::get(, if (!texture): pixelRef ID = 415 
05-03 10:48:05.250 17843-17891/com.aapps.scrollview E/OpenGLRenderer: CacheDebug: generateTexture() in TextureCache::get(, if (!texture): bitmap = 0x55a971acb0 
05-03 10:48:05.250 17843-17891/com.aapps.scrollview E/OpenGLRenderer: CacheDebug: generateTexture() in TextureCache::get(, if (!texture): pixelRef ID = 415 
05-03 10:48:05.850 17843-17891/com.aapps.scrollview E/OpenGLRenderer: CacheDebug: generateTexture() in TextureCache::get(, if (!texture): bitmap = 0x55a971acb0 
05-03 10:48:05.850 17843-17891/com.aapps.scrollview E/OpenGLRenderer: CacheDebug: generateTexture() in TextureCache::get(, if (!texture): pixelRef ID = 415 
05-03 10:48:06.330 17843-17891/com.aapps.scrollview E/OpenGLRenderer: CacheDebug: generateTexture() in TextureCache::get(, if (!texture): bitmap = 0x55a971acb0 
05-03 10:48:06.330 17843-17891/com.aapps.scrollview E/OpenGLRenderer: CacheDebug: generateTexture() in TextureCache::get(, if (!texture): pixelRef ID = 415 
05-03 10:48:06.840 17843-17843/com.aapps.scrollview I/Choreographer: Skipped 30 frames! The application may be doing too much work on its main thread. 
+0

попробовать с добавлением этого андроида: largeHeap = «истина» в вашем приложении тега манифеста –

+0

и прочитать http://developer.android.com/training/displaying-bitmaps/cache-bitmap .html –

ответ

0

положить фон в вашем родителе Layout Container

<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" 
android:background="@drawable/background04" 
tools:context="com.example.scrollview.MainActivity"> 

и удалить ImageView, потому что его больше не нужен

другого наконечник в вашем коде, вы используете слишком много alignParent, вы можете иметь тот же результат, когда вы устанавливаете родительский столбец шириной и высотой и удаляете все свойство alignParent. смотри ниже код изменяет

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:src="@drawable/background04" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.scrollview.MainActivity"> 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/scrollView" > 

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

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="64dp" 
       android:textAppearance="?android:attr/textAppearanceLarge" 
       android:text="Large Text" 
       android:id="@+id/textView" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="64dp" 
       android:textAppearance="?android:attr/textAppearanceLarge" 
       android:text="Large Text" 
       android:id="@+id/textView2" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="64dp" 
       android:textAppearance="?android:attr/textAppearanceLarge" 
       android:text="Large Text" 
       android:id="@+id/textView3" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="64dp" 
       android:textAppearance="?android:attr/textAppearanceLarge" 
       android:text="Large Text" 
       android:id="@+id/textView4" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="64dp" 
       android:textAppearance="?android:attr/textAppearanceLarge" 
       android:text="Large Text" 
       android:id="@+id/textView5" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="64dp" 
       android:textAppearance="?android:attr/textAppearanceLarge" 
       android:text="Large Text" 
       android:id="@+id/textView6" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="64dp" 
       android:textAppearance="?android:attr/textAppearanceLarge" 
       android:text="Large Text" 
       android:id="@+id/textView7" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="64dp" 
       android:textAppearance="?android:attr/textAppearanceLarge" 
       android:text="Large Text" 
       android:id="@+id/textView8" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="64dp" 
       android:textAppearance="?android:attr/textAppearanceLarge" 
       android:text="Large Text" 
       android:id="@+id/textView9" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="64dp" 
       android:textAppearance="?android:attr/textAppearanceLarge" 
       android:text="Large Text" 
       android:id="@+id/textView10" /> 

     </LinearLayout> 

    </ScrollView> 
</RelativeLayout> 
+0

и закрыть родительский контейнер макета с '' – hrskrs

+0

@hrskrs of the course, что не нужно больше говорить. ahahaha –

+0

Как я уже сказал, если мне это нравится, это также работает медленно. –

Смежные вопросы