1

画像の上に画像、ビデオ サム、再生アイコンを配置したい。ビデオのサムネイル画像の中央に再生アイコンを配置したい。FrameLayout を使用していますが、再生アイコンが中央に表示されません。

私のXMLファイル..

<FrameLayout
    android:id="@+id/frameLayout1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <ImageView
        android:id="@+id/imageVideoThumb"
        android:layout_width="120dp"
        android:layout_height="120dp"
        android:src="@drawable/ic_launcher" />

    <ImageView
        android:id="@+id/imagePlayIcon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/video_play_icon" />
</FrameLayout>

どのようにそれを作成することができます, 私を助けてください..

4

4 に答える 4

3

これを試して。このようにXMLファイルに変更するだけです..

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" 
android:layout_gravity="center">

     <ImageView
        android:id="@+id/imageVideoThumb"
        android:layout_width="120dp"
        android:layout_height="120dp"
        android:layout_gravity="center"
        android:src="@drawable/ic_launcher" />

    <ImageView
        android:id="@+id/imagePlayIcon"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:layout_marginLeft="30dp"
        android:layout_marginTop="30dp"
        android:src="@drawable/video_play_icon" />
</RelativeLayout>
于 2013-04-30T09:07:37.697 に答える
1

次のコードを使用する必要があります。

RelativeLayout rv = (RelativeLayout) findViewById(R.id.my_ph);
RelativeLayout.LayoutParams params;
ImageButton im1 = new ImageButton(this);

im1.setBackgroundResource(R.drawable.lamp);
im1.setId(i);
im1.setOnClickListener(new OnClickListener() {
 public void onClick(View v) {
  TextView tx = (TextView) findViewById(R.id.textView1);
  tx.setText("lamp #" + v.getId());
 }
});

 params = new RelativeLayout.LayoutParams(40, 40);
 params.leftMargin = x;
 params.topMargin = y;
 rv.addView(im1, params);

XML レイアウト:

 <RelativeLayout android:id="@+id/my_ph"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content" android:layout_height="wrap_content"    android:gravity="bottom">
    <ImageView android:id="@+id/image" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:layout_alignParentTop="true"
        android:background="@drawable/map" />
    <TextView android:id="@+id/textView1" android:layout_width="wrap_content"  android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:layout_below="@+id/image" android:layout_alignParentLeft="true"></TextView>

于 2013-04-30T08:18:39.090 に答える
0

これはうまくいくはずです。サムネイル画像を親レイアウトとして使用し、gravity: center を設定すると、背景がサムネイルとして設定されている親レイアウトの中心に再生 ImageView が配置されます

<FrameLayout
        android:id="@+id/frameLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <RelativeLayout
            android:id="@+id/imageVideoThumb"
            android:layout_width="120dp"
            android:layout_height="120dp"
            android:background="@drawable/ic_launcher" 
            android:gravity="center"/>

        <ImageView
            android:id="@+id/imagePlayIcon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/video_play_icon" />
    </RelativeLayout>
    </FrameLayout>
于 2013-04-30T08:29:59.617 に答える
0

を設定して、それらを中央に揃えることができGravityます。ImagesViews

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/frameLayout1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <ImageView
      android:id="@+id/imageVideoThumb"
      android:layout_width="120dp"
      android:layout_height="120dp"
      android:layout_gravity="center"
      android:background="@drawable/ic_launcher"  />

    <ImageView
        android:id="@+id/imagePlayIcon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:background="@drawable/video_play_icon" />

</FrameLayout>
于 2013-04-30T08:30:30.187 に答える