Android 如何在ScrollView中的ImageView上动态添加按钮?安卓沙马林
我有一个axml文件:Android 如何在ScrollView中的ImageView上动态添加按钮?安卓沙马林,android,android-layout,xamarin,imageview,scrollview,Android,Android Layout,Xamarin,Imageview,Scrollview,我有一个axml文件: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mylinearlayout" android:orientation="vertical" android:configChanges="orientation|keyboardHidden" android:layout_width="fill_parent" android:layo
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mylinearlayout"
android:orientation="vertical"
android:configChanges="orientation|keyboardHidden"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<SurfaceView
android:id="@+id/surfaceView"
android:layout_height="1dip"
android:layout_width="1dip" />
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/scrollView1">
<LinearLayout
android:id="@+id/filesScrollerLayout"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</ScrollView>
<VideoView
android:layout_width="1dip"
android:layout_height="1dip"
android:id="@+id/videoView1" />
如何在LinearLayuot中动态地将按钮置于此图像视图上以启动视频?
谢谢。不要在
线性布局中添加图像视图
,而是添加一个自定义布局,在该布局中,您的图像视图
以及顶部的按钮
定义列表中每个项目的布局:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</RelativeLayout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</RelativeLayout>
private void addBitmapToLayout(Bitmap bitmap) {
LayoutInflater inflater = LayoutInflater.from(context);
RelativeLayout layout = inflater.inflate(R.layout.list_item, null, false);
ImageView iv = (ImageView) layout.findViewById(R.id.imageView);
iv.SetImageBitmap(bitmap);
//Add click listener to your Button etc...
Button button = (Button) layout.findViewById(R.id.button);
linearlayout.AddView(layout);
}