Android 安卓中的图像对图像
我想把图像放在图像上,视频拇指和播放图标放在上面。 我想把播放图标放在视频拇指图像的中心。我正在使用FrameLayout,但播放图标不在中间查看 我的XML文件Android 安卓中的图像对图像,android,imageview,android-framelayout,Android,Imageview,Android Framelayout,我想把图像放在图像上,视频拇指和播放图标放在上面。 我想把播放图标放在视频拇指图像的中心。我正在使用FrameLayout,但播放图标不在中间查看 我的XML文件 <FrameLayout android:id="@+id/frameLayout1" android:layout_width="wrap_content" android:layout_height="wrap_content" > <ImageView andr
<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>
如何创建它,请帮助我。您需要使用以下代码:
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>
您需要使用以下代码:
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>
我想这应该行得通。
将缩略图图像用作父布局并设置“重力:中心”,将使播放图像视图与父布局的中心对齐,父布局的背景设置为缩略图
<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>
我想这应该行得通。
将缩略图图像用作父布局并设置“重力:中心”,将使播放图像视图与父布局的中心对齐,父布局的背景设置为缩略图
<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>
您可以设置
图像视图的重力
,使其在中心对齐:
<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>
您可以设置图像视图的重力
,使其在中心对齐:
<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>
试试这个。只需像这样切换到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>
试试这个。只需像这样切换到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>
是的,因为框架布局不是这样做的。它不会将项目放置在中心。它将然后放置在左上角。是的,因为framelayout不是这样做的。它不会将项目放置在中心。然后将其放置在左上角。