小编use*_*474的帖子

如何以编程方式创建具有id和src参数的imageView?

以下工作,但我想消除xml,以便我可以编程方式更改图像:Java:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.p6_touch);
    ImageView floatImage = (ImageView) findViewById(R.id.p6_imageView);
    floatImage.setOnTouchListener(this);    
}
Run Code Online (Sandbox Code Playgroud)

XML:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/background_black" >
    <ImageView
        android:id="@+id/p6_imageView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scaleType="matrix"
        android:src="@drawable/p6_trail_map" >
    </ImageView>
    <ImageView
          android:id="@+id/imageView1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="bottom"
          android:onClick="showFlashlight"
          android:src="@drawable/legend_block24" />
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

android android-layout android-imageview android-framelayout

5
推荐指数
1
解决办法
3万
查看次数

XML如何包含惊叹号!在XML文本字符串中?逃脱序列?

我尝试了许多转义序列组合,以便在Android资源文件夹中的xml字符串中获得惊叹号 - 无济于事.您将使用什么xml字符串来获取帮助!例如?谢谢...

xml

3
推荐指数
1
解决办法
6665
查看次数