【问题标题】:How to use ListPrefference to select an Image for Live Wallpaper background [duplicate]如何使用 ListPreference 为动态壁纸背景选择图像 [重复]
【发布时间】:2015-03-11 15:01:55
【问题描述】:

我正在制作动态壁纸。 在此,我希望用户选择一个背景图像和一些其他图像在背景图像上旋转/移动。

我想通过首选项显示 4-6 张图像的列表,用户可以在其中选择一个。我想在后台设置用户选择的图像。

我该怎么做。 我应该使用 ListPreference 吗?

我阅读了Choosing background for Live Wallpaper,但无法使用。

谢谢

【问题讨论】:

    标签: android preferences live-wallpaper


    【解决方案1】:

    How to add a button to PreferenceScreen

    为我工作。

    在按钮的地方我使用了 TextView 并添加了 ImageView。

    <LinearLayout 
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_marginTop="15dp"
              android:orientation="horizontal">
    
            <ImageView
                android:id="@+id/imageView1"
                android:layout_width="150dp"
                android:layout_height="200dp"
                android:layout_gravity="center_horizontal"
                android:src="@drawable/background1" 
                android:layout_weight="1"
                android:onClick="imageClicked1"/>
    
            <ImageView
                android:id="@+id/imageView2"
                android:layout_width="150dp"
                android:layout_height="200dp"
                android:layout_gravity="center_horizontal"
                android:src="@drawable/background2" 
                android:layout_weight="1"
                android:onClick="imageClicked2"/>
    
    
     </LinearLayout>
    
    
     <LinearLayout 
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_marginTop="15dp"
              android:orientation="horizontal">
    
            <ImageView
                android:id="@+id/imageView3"
                android:layout_width="150dp"
                android:layout_height="200dp"
                android:layout_gravity="center_horizontal"
                android:src="@drawable/background3" 
                android:layout_weight="1"
                android:onClick="imageClicked3"/>
    
            <ImageView
                android:id="@+id/imageView4"
                android:layout_width="150dp"
                android:layout_height="200dp"
                android:layout_weight="1"
                android:onClick="imageClicked4"
                android:src="@drawable/background4" />
    
        </LinearLayout> 
    
      <ListView android:id="@android:id/list"
        android:visibility="invisible"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent" />
      </LinearLayout>
    

    并实现了onClick事件的方法 例如对于第一个 imageView

          public void imageClicked1(View V)
          {
              Toast.makeText(this, "Image Clciked 1", Toast.LENGTH_LONG).show();
    
              shfEditorObject.putInt("IMAGE", 1);
              shfEditorObject.commit();
          }
    

    然后从 sharedpreference 中获取图像并设置为背景。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多