搭建直播平台,情景模式界面设计
搭建直播平台,情景模式界面设计
1.activity_main.xml
1 | <br><!-- 主界面的布局整体为线性布局 --><br><LinearLayout xmlns:android= "http://schemas.android.com/apk/res/android" <br> xmlns:tools= "http://schemas.android.com/tools" <br> android:layout_width= "match_parent" <br> android:layout_height= "match_parent" <br> <br> android:background= "@drawable/bg" <br> android:orientation= "vertical" <br> tools:context= ".MainActivity" ><br><!--普通情景模式的布局 单选按钮组 --><br> <RadioGroup<br> android:id= "@+id/group1" <br> android:layout_width= "match_parent" <br> android:layout_height= "match_parent" <br> android:background= "@drawable/bg" ><br> <br> <RadioButton<br> android:id= "@+id/radioButton1" <br> android:layout_width= "wrap_content" <br> android:layout_height= "wrap_content" <br> android:text= "铃声和振动" /><br> <br> <RadioButton<br> android:id= "@+id/radioButton2" <br> android:layout_width= "wrap_content" <br> android:layout_height= "wrap_content" <br> android:text= "铃声" /><br> <br> <RadioButton<br> android:id= "@+id/radioButton3" <br> android:layout_width= "wrap_content" <br> android:layout_height= "wrap_content" <br> android:text= "振动" /><br> <br> <RadioButton<br> android:id= "@+id/radioButton4" <br> android:layout_width= "wrap_content" <br> android:layout_height= "wrap_content" <br> android:text= "静音" /><br> </RadioGroup><br><!-- 定时情景模式的布局 --><br> <LinearLayout<br> android:id= "@+id/second" <br> android:layout_width= "match_parent" <br> android:layout_height= "match_parent" <br> android:background= "@drawable/bg" <br> android:orientation= "vertical" ><br> <br> <TextView<br> android:id= "@+id/shezhi" <br> android:layout_width= "wrap_content" <br> android:layout_height= "wrap_content" <br> android:text= "设置时间:" /><br><!-- 时钟 --><br> <TimePicker<br> android:id= "@+id/timePicker1" <br> android:layout_width= "wrap_content" <br> android:layout_height= "wrap_content" /><br> <br> <RadioGroup<br> android:id= "@+id/group2" <br> android:layout_width= "match_parent" <br> android:layout_height= "match_parent" ><br> <br> <RadioButton<br> android:layout_width= "wrap_content" <br> android:layout_height= "wrap_content" <br> android:text= "铃声和振动" /><br> <br> <RadioButton<br> android:layout_width= "wrap_content" <br> android:layout_height= "wrap_content" <br> android:text= "铃声" /><br> <br> <RadioButton<br> android:layout_width= "wrap_content" <br> android:layout_height= "wrap_content" <br> android:text= "振动" /><br> <br> <RadioButton<br> android:layout_width= "wrap_content" <br> android:layout_height= "wrap_content" <br> android:text= "静音" /><br> </RadioGroup><br> </LinearLayout><br><!-- 自定义情景模式布局 --><br> <LinearLayout<br> android:id= "@+id/third" <br> android:layout_width= "match_parent" <br> android:layout_height= "match_parent" <br> android:layout_marginTop= "30dp" <br> android:background= "@drawable/bg" <br> android:orientation= "vertical" ><br> <br> <LinearLayout<br> android:layout_width= "wrap_content" <br> android:layout_height= "wrap_content" <br> android:layout_marginTop= "30dp" <br> android:orientation= "horizontal" ><br> <br> <TextView<br> android:id= "@+id/textView1" <br> android:layout_width= "wrap_content" <br> android:layout_height= "wrap_content" <br> android:text= "情景模式:" /><br> <br> <ImageView<br> android:id= "@+id/imageView1" <br> android:layout_width= "wrap_content" <br> android:layout_height= "wrap_content" <br> android:layout_marginLeft= "40dp" <br> android:src= "@drawable/icon" /><br> </LinearLayout><br> <br> <LinearLayout<br> android:layout_width= "wrap_content" <br> android:layout_height= "wrap_content" <br> android:layout_marginTop= "30dp" <br> android:orientation= "horizontal" ><br> <br> <TextView<br> android:id= "@+id/textView2" <br> android:layout_width= "wrap_content" <br> android:layout_height= "wrap_content" <br> android:text= "声音音量:" /><br> <br> <ProgressBar<br> android:id= "@+id/progressBar1" <br> style= "?android:attr/progressBarStyleHorizontal" <br> android:layout_width= "200dp" <br> android:layout_height= "20dp" <br> android:progress= "20" <br> android:visibility= "visible" /><br> </LinearLayout><br><!-- 图片按钮水平布局 --><br> <LinearLayout<br> android:layout_width= "wrap_content" <br> android:layout_height= "wrap_content" <br> android:layout_marginLeft= "40dp" <br> android:layout_marginTop= "30dp" <br> android:orientation= "horizontal" ><br> <br> <ImageButton<br> android:id= "@+id/imageButton1" <br> android:layout_width= "wrap_content" <br> android:layout_height= "wrap_content" <br> android:src= "@drawable/down" /><br> <br> <ImageButton<br> android:id= "@+id/imageButton2" <br> android:layout_width= "wrap_content" <br> android:layout_height= "wrap_content" <br> android:src= "@drawable/up" /><br> </LinearLayout><br><!-- 图片按钮水平布局 --><br> <LinearLayout<br> android:layout_width= "wrap_content" <br> android:layout_height= "wrap_content" <br> android:layout_marginLeft= "40dp" <br> android:layout_marginTop= "20dp" <br> android:orientation= "horizontal" ><br> <br> <ImageButton<br> android:id= "@+id/imageButton3" <br> android:layout_width= "wrap_content" <br> android:layout_height= "wrap_content" <br> android:clickable= "true" <br> android:src= "@drawable/icon" /><br> <br> <ImageButton<br> android:id= "@+id/imageButton4" <br> android:layout_width= "wrap_content" <br> android:layout_height= "wrap_content" <br> android:src= "@drawable/mute" /><br> <br> <ImageButton<br> android:id= "@+id/imageButton5" <br> android:layout_width= "wrap_content" <br> android:layout_height= "wrap_content" <br> android:src= "@drawable/vibrate" /><br> </LinearLayout><br> </LinearLayout><br> <br></LinearLayout> |
2.MainActivity.java源代码
1 | <br>package com.example.myring;<br> <br>import android.media.AudioManager;<br>import android.os.Bundle;<br> <br>import android.app.AlarmManager;<br>import android.app.TabActivity;<br>import android.content.Context;<br>import android.view.LayoutInflater;<br>import android.view.Menu;<br>import android.view.View;<br>import android.view.View.OnClickListener;<br>import android.widget.ImageButton;<br>import android.widget.ImageView;<br>import android.widget.ProgressBar;<br>import android.widget.RadioGroup;<br>import android.widget.TabHost;<br>import android.widget.RadioGroup.OnCheckedChangeListener;<br>import android.widget.TabHost.OnTabChangeListener;<br>import android.widget.TimePicker;<br> <br> public class MainActivity extends TabActivity {<br> private ImageView imageView1;<br> private ImageButton imageButton1;<br> private ImageButton imageButton2;<br> private ImageButton imageButton3;<br> private ImageButton imageButton4;<br> private ImageButton imageButton5;<br>@Override<br> protected void onCreate(Bundle savedInstanceState) {<br>super.onCreate(savedInstanceState);<br>imageView1=(ImageView) this.findViewById(R.id.imageView1);<br>imageButton1=(ImageButton)this.findViewById(R.id.imageButton1);<br>imageButton2=(ImageButton)this.findViewById(R.id.imageButton2);<br>imageButton3=(ImageButton)this.findViewById(R.id.imageButton3);<br>imageButton4=(ImageButton)this.findViewById(R.id.imageButton4);<br>imageButton5=(ImageButton)this.findViewById(R.id.imageButton5);<br> final TabHost tabHost = getTabHost();<br>LayoutInflater inflater = LayoutInflater.from(this);<br>inflater.inflate(R.layout.activity_main, tabHost.getTabContentView());<br>TabHost.TabSpec tab01 = tabHost.newTabSpec( "tab01" )<br>.setIndicator( "普通情景模式" , getResources().getDrawable(R.drawable.icon))<br>.setContent(R.id.group1);<br> <br>TabHost.TabSpec tab02 = tabHost.newTabSpec( "tab02" )<br>.setIndicator( "定时情景模式" ,getResources().getDrawable(R.drawable.timeprofile))<br>.setContent(R.id.second);<br>TabHost.TabSpec tab03 = tabHost.newTabSpec( "tab03" )<br>.setIndicator( "自定义情景模式" , getResources().getDrawable(R.drawable.addprofile))<br>.setContent(R.id.third);<br> //将创建好的Tab对象放入到tabHost中<br>tabHost.addTab(tab01);<br>tabHost.addTab(tab02);<br>tabHost.addTab(tab03);<br>tabHost.setCurrentTab(0);<br>tabHost.setBackgroundResource(R.drawable.bg);<br>}<br> <br> <br> <br> <br> <br>@Override<br>public boolean onCreateOptionsMenu(Menu menu) {<br>// Inflate the menu; this adds items to the action bar if it is present.<br>getMenuInflater().inflate(R.menu.main, menu);<br>return true;<br>}<br> <br>} |
以上就是搭建直播平台,情景模式界面设计, 更多内容欢迎关注之后的文章
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现