【问题标题】:How to add a button over an ImageView in ScrollView dynamically? Android. Xamarin如何在 ScrollView 中的 ImageView 上动态添加按钮?安卓。赛马林
【发布时间】:2016-04-17 10:43:15
【问题描述】:

我有一个 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: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" />

我的应用程序拍摄照片和视频并将其放入 LinearLayout。

我在添加视频的时候,动态的创建一个ImageView,把视频的第一帧放到这个ImageView中,然后添加到LinearLayout中。

private void addBitmapToLayout(Bitmap bitmap)
{
    ImageView iv = new ImageView(this);
    iv.SetImageBitmap(bitmap);
    linearlayout.AddView(iv);
}

如何在 LinearLayuot 中的这个 ImageView 上动态放置一个按钮来启动视频? Like this 谢谢。

【问题讨论】:

    标签: android android-layout xamarin imageview scrollview


    【解决方案1】:

    不要将ImageView 添加到您的LinearLayout,而是添加一个自定义布局,您将在其中将您的ImageView 以及Button 放在顶部

    为列表中的每个项目定义布局:

    <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);
    }
    

    【讨论】:

      猜你喜欢
      • 2020-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-21
      • 1970-01-01
      • 2018-03-04
      • 2011-09-17
      相关资源
      最近更新 更多