android > layout > background 背景图片重复

探讨了在Android中使用控件顶部栏背景图的方法,包括直接加载图片为背景与加载样式之间的区别,以及如何实现repeat效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

contrl_index_top_bar_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/contrl_top_bar_bg"
    android:tileMode="repeat" />
 
调用
  	    <RelativeLayout 
	        android:layout_width="fill_parent"
	        android:layout_height="fill_parent"
	        android:layout_weight="9" 
	        android:background="@drawable/contrl_index_top_bar_bg"
	        > 
		   
	    </RelativeLayout> 
 

实际上在 android 中, 即便 直接  android:background = "@drawable/contrl_top_bar_bg"   也可以达到效果,
区别是,   直接 加载图片 为背景会将 图片 以一定比例 显示完整即会被拉伸,   加载 style 的话则 以原有布局的大小不变,图片 大小不变 镶嵌其中,会出现repeat效果类似 HTML 里面的 CSS 背景图片  









 


 





 







 

数字按钮从0-9进行初始化,请使用最简单的方法进行初始化<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:orientation="horizontal" android:layout_height="100dp"> <TextView android:id="@+id/input" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_marginTop="10dp" android:text="" android:textSize="30sp" /> <TextView android:id="@+id/result" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="195dp" android:layout_marginTop="50dp" android:text="" android:textSize="30sp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:orientation="horizontal" android:layout_height="80dp"> <TextView android:id="@+id/C" android:onClick="oneOnClick" android:layout_width="0dp" android:layout_weight="1" android:layout_height="match_parent" android:gravity="center" android:textSize="30sp" android:text="C"/> <!-- android:background="@drawable/selector_gray1"--> <TextView android:id="@+id/zf" android:onClick="oneOnClick" android:layout_width="0dp" android:layout_weight="1" android:layout_height="match_parent" android:gravity="center" android:textSize="30sp" android:text="+/-"/> <!-- android:background="@drawable/selector_gray1"--> <TextView android:id="@+id/mo" andro
03-10
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/main" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"> <!-- 语言选择器 --> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:orientation="horizontal"> <Spinner android:id="@+id/language_spinner1" android:layout_width="0dp" android:layout_height="50dp" android:layout_marginRight="10dp" android:layout_weight="1" /> <Spinner android:id="@+id/language_spinner2" android:layout_width="0dp" android:layout_height="50dp" android:layout_marginLeft="10dp" android:layout_weight="1" /> </LinearLayout> <!-- 消息列表(占满中间空间) --> <ListView android:id="@+id/messageListView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:divider="@android:color/transparent" android:dividerHeight="8dp" android:padding="16dp" /> <!-- 用ScrollView包裹输入区域,确保键盘弹出时可滚动 --> <ScrollView android:layout_width="match_parent" android:layout_height="wrap_content" android:fillViewport="true"> <!-- 关键:确保ScrollView占满可用空间 --> <!-- 输入区域 --> <LinearLayout android:id="@+id/line1" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#F5F5F5" android:orientation="horizontal" android:padding="8dp"> <!-- 语音/键盘切换按钮 --> <ImageButton android:id="@+id/voiceTextToggleButton" android:layout_width="35dp" android:layout_height="35dp" android:layout_gravity="center_vertical" android:background="@mipmap/icon_shengbo" android:padding="8dp" /> <!-- 文字输入框 --> <EditText android:id="@+id/textInputEditText" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginLeft="4dp" android:layout_marginRight="4dp" android:layout_weight="1" android:background="@android:color/white" android:ems="10" android:gravity="top" android:hint="输入消息..." android:minHeight="35dp" android:padding="12dp" /> <!-- 语音输入按钮(默认隐藏) --> <Button android:id="@+id/recordButton" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginLeft="4dp" android:layout_marginRight="4dp" android:layout_weight="1" android:text="按住 说话" android:textColor="#FFFFFF" android:visibility="gone" android:textSize="16sp" /> </LinearLayout> </ScrollView> </LinearLayout>当键盘弹起时输入框与键盘之间有很大空隙如何解决
最新发布
07-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值