2016-04-17 5 views
0

habe ich eine axml Datei:Wie fügt man dynamisch eine Schaltfläche über ein ImageView in ScrollView hinzu? Android. Xamarin

<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" /> 

nimmt Meine Anwendung ein Foto und Video und legt es in dem Linearlayout.

Wenn ich Video hinzufüge, erstelle ich dynamisch ein ImageView, lege den ersten Frame des Videos in dieses ImageView und füge es in LinearLayout hinzu.

Wie kann ich einen Button über dieses ImageView in LinearLayuot dynamisch setzen, um das Video zu starten? Like this Vielen Dank.

Antwort

0

Statt eine ImageView auf Ihre LinearLayout hinzuzufügen, einen benutzerdefinierten Layout hinzufügen, wo Sie Ihre ImageView sowie eine Button auf

Definieren Sie das Layout für jedes Element in Ihrer Liste haben werden:

<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> 

Ihre Funktion wird jetzt:

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