我是Android的新手。
我想知道是否可以在ImageView上放置按钮或其他组件。我已经尝试将图像设置为LinearLayout的背景图像,但是当我在横向和纵向模式之间切换时,图像部分会发生变化。
非常感谢。
答案 0 :(得分:39)
不要将图像作为背景,您无法控制图像的缩放方式。相反,创建一个RelativeLayout,并将ImageView作为子项之一,您可以将任何内容(按钮等)放置为其他RelativeLayout子项。
<RelativeLayout ...>
<ImageView (your image) ...>
<Button (the button you want) ... />
</RelativeLayout>
答案 1 :(得分:4)
试试这段代码......它可以帮助你......
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/imageviewMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="Path "
/>
<Button android:id="@+id/but2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
试试此代码.....
在按钮中输入参数来设置按钮位置....
android:layout_margin or android:layout_alignParent
并且还给出了Image of Image ....
答案 2 :(得分:3)
答案 3 :(得分:2)
最简单的方法是使用FrameLayout
。
答案 4 :(得分:0)
使用 @SpringBootApplication
public class YourApplicationName{
public static void main(String[] args) {
SpringApplication.run(MobileAppWsApplication.class, args);
}
@Bean
public BCryptPasswordEncoder bCryptPasswordEncoder() {
return new BCryptPasswordEncoder();
}
}
很容易。
ConstraintLayout
的约束设置为Button
。ImageView
拖到Button
上的任何位置以将其定位。