① 如何實現android中三個單選按鈕橫向排列且只能選一個
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/row_item_margin">
<TextView
android:id="@+id/tvStorageWay"
style="@style/EditTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="儲存方式:"/>
<RadioGroup
android:id="@+id/rgStorageWay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/tvStorageWay"
android:gravity="center_vertical"
android:orientation="horizontal">
<RadioButton
android:id="@+id/rbPack"
style="@style/EditTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@null"
android:drawableLeft="@drawable/selector_login_mode_radiobutton"
android:text="包裝"/>
<RadioButton
android:id="@+id/rbBulk"
style="@style/EditTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/row_item_margin"
android:layout_weight="1"
android:button="@null"
android:drawableLeft="@drawable/selector_login_mode_radiobutton"
android:text="散裝"/>
<RadioButton
android:id="@+id/rbStorageWayOther"
style="@style/EditTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/row_item_margin"
android:layout_weight="1"
android:button="@null"
android:drawableLeft="@drawable/selector_login_mode_radiobutton"
android:text="其它"/>
</RadioGroup>
</RelativeLayout>
② Android studio怎麼設置代碼橫向選擇和豎向選擇
1、在Android studio進行選擇進行選擇的代碼的文件,並進行打開。
2、在編輯器的代碼中選擇列的的內容之後,可是在選擇列的內容時候,會把行的內容全部選中。
3、在進行點擊Android studio菜單中的「edit」的選項菜單中。
4、進行點擊完edit的選項菜單中之後,就會彈出了一個下拉菜單中進行選擇「column
selection mode」的選項。
5、這樣的話,就可以在Android studio的底部的位置,可以看到的是已經變為了column的模式。
6、在次在列表中選擇列表中內容,可以看到了行的內容沒有全部選擇進入,說明選擇縱向模式設置成功。
③ android怎麼在代碼中設置狀態選擇器
這個是非常簡單的,只需要按照下面的步驟進行即可。
首先新建一個狀態選擇器,創建在drawable目錄下,創建的格式如下:,記住創建時的名字,待會要使用。
<spanstyle="font-size:14px;"><?xmlversion="1.0"encoding="utf-8"?>
<selectorxmlns:android="http://schemas.android.com/apk/res/android">
<itemandroid:drawable="@drawable/function_greenbutton_pressed"android:state_pressed="true"/>//按下的圖片
<!--pressed-->
<itemandroid:drawable="@drawable/function_greenbutton_pressed"android:state_focused="true"/>//獲取焦點的圖片
<!--focused-->
<itemandroid:drawable="@drawable/function_greenbutton_normal"/>
<!--default-->//默認圖片
</selector>
然後在布局文件中創建一個button控制項
java"><Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn"/>
由於View類中PRESSED_ENABLED_STATE_SET值不是公共常量,所以通過繼承來實現。
classMyButtonextendsView{
publicMyButton(Contextcontext){
super(context);
}
//以下這個方法也可以把你的圖片數組傳過來,以StateListDrawable來設置圖片狀態,來表現button的各中狀態。未選
//中,按下,選中效果。
publicStateListDrawablesetbg(Integer[]mImageIds){
StateListDrawablebg=newStateListDrawable();
Drawablenormal=this.getResources().getDrawable(mImageIds[0]);
Drawableselected=this.getResources().getDrawable(mImageIds[1]);
Drawablepressed=this.getResources().getDrawable(mImageIds[2]);
bg.addState(View.PRESSED_ENABLED_STATE_SET,pressed);
bg.addState(View.ENABLED_FOCUSED_STATE_SET,selected);
bg.addState(View.ENABLED_STATE_SET,normal);
bg.addState(View.FOCUSED_STATE_SET,selected);
bg.addState(View.EMPTY_STATE_SET,normal);
returnbg;
}
}
然後執行下面的代碼即可成功設置狀態選擇器
Integer[]mButtonState={R.drawable.defaultbutton,
R.drawable.focusedpressed,R.drawable.pressed};
ButtonmButton=(Button)findViewById(R.id.button);
MyButtonmyButton=newMyButton(this);
mButton.setBackgroundDrawable(myButton.setbg(mButtonState));
④ android中horizontal和vertical的區別
當 android:orientation="vertical" 時, 只有水平方向的設置才起作用,垂直方向的設置不起作用。即:left,right,center_horizontal 是生效的。
當 android:orientation="horizontal" 時, 只有垂直方向的設置才起作用,水平方向的設置不起作用。即:top,bottom,center_vertical 是生效的。
⑤ android 怎麼使布局橫向顯示
如果你要固定使界面橫向的話,可在AndroidMenifest.xml中對應用布局的Activity進行如下定義
<activity android:name="xxxx"
android:screenOrientation="landscape">
</activity>
screenOrientation的值有以下幾種:
landscape:橫向
portrait:縱向
⑥ 如何設置android界面橫屏顯示
全屏
在Activity的onCreate方法中的setContentView(myview)調用之前添加下面代碼
requestWindowFeature(Window.FEATURE_NO_TITLE);//隱藏標題
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);//設置全屏
橫屏
按照下面代碼示例修改Activity的onResume方法
@Override
protected void onResume() {
/**
* 設置為橫屏
*/
if(getRequestedOrientation()!=ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE){
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
super.onResume();
}
或者在配置文件中對Activity節點添加android:screenOrientation屬性(landscape是橫向,portrait是縱向)
android:launchMode="singleTask" android:screenOrientation="portrait">
要設置成豎屏設置成 SCREEN_ORIENTATION_PORTRAIT
// ----------------
常亮
view.setKeepScreenOn(true)
不加任何旋轉屏幕的處理代碼的時候,旋轉屏幕將會導致系統把當前activity關閉,重新打開。
如果只是簡單的界面調整,我們可以阻止此問題的發生,屏幕旋轉而自己調整屏幕的元素重構。
首先我們需要修改AndroidManifest.xml文件:
<activity android:name=".Magazine">
</activity>
//修改為:
<activity android:name=".Magazine"
android:configChanges="orientation|keyboard">
</activity>
這樣是讓程序能夠響應旋轉屏幕的事件。
然後重寫onConfigurationChanged方法:
@Override
public void onConfigurationChanged(Configuration newConfig) {
// TODO Auto-generated method stub
super.onConfigurationChanged(newConfig);
Log.v(" == onConfigurationChanged");
processLayout();
}
//----------------------------
在我們用Android開發過程中,會碰到Activity在切換到後台或布局從橫屏LANDSCAPE切換到PORTRAIT,會重新切換Activity會觸發一次onCreate方法。
在Android開發中這種情況視可以避免的,我們可以在androidmanifest.xml中的activit元素加入這個屬性 android:configChanges="orientation|keyboardHidden" 就能有效避免oncreat方法的重復載入,
androidmanifest.xml內容如下:紅色字體為添加部分
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.demo"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".DemoGPS"
android:configChanges="orientation|keyboardHidden"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-library android:name="com.google.android.maps" />
</application>
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
</manifest>
同時在Activity的Java文件中重載onConfigurationChanged(Configuration newConfig)這個方法,這樣就不會在布局切換或窗口切換時重載等方法。代碼如下:
@Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
{
//land
}
else if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT)
{
//port
}
}
//------------------------------------------------------
關於Android中Activity的橫豎屏切換問題可以通過AndroidManifest.xml文件中的Activity來配置:
android:screenOrientation=["unspecified" | "user" | "behind" |
"landscape" | "portrait" |
"sensor" | "nonsensor"]
screenOrientation 用來指定Activity的在設備上顯示的方向,每個值代表如下含義:
"unspecified" 默認值 由系統來判斷顯示方向.判定的策略是和設備相關的,所以不同的設備會有不同的顯示方向.
"landscape" 橫屏顯示(寬比高要長)
"portrait" 豎屏顯示(高比寬要長)
"user" 用戶當前首選的方向
"behind" 和該Activity下面的那個Activity的方向一致(在Activity堆棧中的)
"sensor" 有物理的感應器來決定。如果用戶旋轉設備這屏幕會橫豎屏切換。
"nosensor" 忽略物理感應器,這樣就不會隨著用戶旋轉設備而更改了 ( "unspecified"設置除外 )。
更多安卓例子請去360手機助手下載安卓學習手冊,裡面有橫豎排例子,源碼,例子隨便看。
⑦ android中的checkbox如何設置橫向顯示
LinearLayout有一個屬性,是整個layout內View的排列方向的
android:orientation="vertical",為豎向的,默認。
android:orientation="horizontal",才為橫向的
你需在Layout的xml配置上加上這句
⑧ android 中RadioGroup怎麼實現橫排按鈕
給RadioGroup加一個屬性: android:orientation="horizontal" 這樣就可以把裡面的RadioButton橫排了。
⑨ android橫向下拉框怎麼做的
用popwindow,或者spiner.這兩個控制項可以作為某個控制項的下拉彈出。spiner是一個列表,popwindow更強大一點,可以自定義布局。另外還有一個控制項是帶有下拉列表的Listview怎麼拼寫我忘了好像是 "E啥啥啥Listview"