搭建直播平臺,情景模式介面設計

zhibo系統開發發表於2023-01-16

搭建直播平臺,情景模式介面設計

1.activity_main.xml

<!-- 主介面的佈局整體為線性佈局 -->
<LinearLayout xmlns:android="
    xmlns:tools="
    android:layout_width="match_parent"
    android:layout_height="match_parent"
   
    android:background="@drawable/bg"
    android:orientation="vertical"
    tools:context=".MainActivity" >
<!--普通情景模式的佈局 單選按鈕組 -->
    <RadioGroup
        android:id="@+id/group1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/bg" >
 
        <RadioButton
            android:id="@+id/radioButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="鈴聲和振動" />
 
        <RadioButton
            android:id="@+id/radioButton2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="鈴聲" />
 
        <RadioButton
            android:id="@+id/radioButton3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="振動" />
 
        <RadioButton
            android:id="@+id/radioButton4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="靜音" />
    </RadioGroup>
<!-- 定時情景模式的佈局 -->
    <LinearLayout
        android:id="@+id/second"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/bg"
        android:orientation="vertical" >
 
        <TextView
            android:id="@+id/shezhi"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="設定時間:" />
<!-- 時鐘 -->
        <TimePicker
            android:id="@+id/timePicker1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
 
        <RadioGroup
            android:id="@+id/group2"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
 
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="鈴聲和振動" />
 
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="鈴聲" />
 
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="振動" />
 
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="靜音" />
        </RadioGroup>
    </LinearLayout>
<!-- 自定義情景模式佈局 -->
    <LinearLayout
        android:id="@+id/third"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="30dp"
        android:background="@drawable/bg"
        android:orientation="vertical" >
 
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="30dp"
            android:orientation="horizontal" >
 
            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="情景模式:" />
 
            <ImageView
                android:id="@+id/imageView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="40dp"
                android:src="@drawable/icon" />
        </LinearLayout>
 
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="30dp"
            android:orientation="horizontal" >
 
            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="聲音音量:" />
 
            <ProgressBar
                android:id="@+id/progressBar1"
                style="?android:attr/progressBarStyleHorizontal"
                android:layout_width="200dp"
                android:layout_height="20dp"
                android:progress="20"
                android:visibility="visible" />
        </LinearLayout>
<!-- 圖片按鈕水平佈局 -->
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="40dp"
            android:layout_marginTop="30dp"
            android:orientation="horizontal" >
 
            <ImageButton
                android:id="@+id/imageButton1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/down" />
 
            <ImageButton
                android:id="@+id/imageButton2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/up" />
        </LinearLayout>
<!-- 圖片按鈕水平佈局 -->
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="40dp"
            android:layout_marginTop="20dp"
            android:orientation="horizontal" >
 
            <ImageButton
                android:id="@+id/imageButton3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:clickable="true"
                android:src="@drawable/icon" />
 
            <ImageButton
                android:id="@+id/imageButton4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/mute" />
 
            <ImageButton
                android:id="@+id/imageButton5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/vibrate" />
        </LinearLayout>
    </LinearLayout>
 
</LinearLayout>


2.MainActivity.java原始碼

package com.example.myring;
 
import android.media.AudioManager;
import android.os.Bundle;
 
import android.app.AlarmManager;
import android.app.TabActivity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RadioGroup;
import android.widget.TabHost;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TimePicker;
 
public class MainActivity extends TabActivity {
private ImageView imageView1;
private ImageButton imageButton1;
private ImageButton imageButton2;
private ImageButton imageButton3;
private ImageButton imageButton4;
private ImageButton imageButton5;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
imageView1=(ImageView) this.findViewById(R.id.imageView1);
imageButton1=(ImageButton)this.findViewById(R.id.imageButton1);
imageButton2=(ImageButton)this.findViewById(R.id.imageButton2);
imageButton3=(ImageButton)this.findViewById(R.id.imageButton3);
imageButton4=(ImageButton)this.findViewById(R.id.imageButton4);
imageButton5=(ImageButton)this.findViewById(R.id.imageButton5);
final TabHost tabHost = getTabHost();
LayoutInflater inflater = LayoutInflater.from(this);
inflater.inflate(R.layout.activity_main, tabHost.getTabContentView());
TabHost.TabSpec tab01 = tabHost.newTabSpec("tab01")
.setIndicator("普通情景模式", getResources().getDrawable(R.drawable.icon))
.setContent(R.id.group1);
 
TabHost.TabSpec tab02 = tabHost.newTabSpec("tab02")
.setIndicator("定時情景模式",getResources().getDrawable(R.drawable.timeprofile))
.setContent(R.id.second);
TabHost.TabSpec tab03 = tabHost.newTabSpec("tab03")
.setIndicator("自定義情景模式", getResources().getDrawable(R.drawable.addprofile))
.setContent(R.id.third);
//將建立好的Tab物件放入到tabHost中
tabHost.addTab(tab01);
tabHost.addTab(tab02);
tabHost.addTab(tab03);
tabHost.setCurrentTab(0);
tabHost.setBackgroundResource(R.drawable.bg);
}
 
 
    
  
  
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
 
}


以上就是搭建直播平臺,情景模式介面設計, 更多內容歡迎關注之後的文章


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69978258/viewspace-2932292/,如需轉載,請註明出處,否則將追究法律責任。

相關文章