导航:首页 > 操作系统 > android横向选择器

android横向选择器

发布时间:2022-06-19 14:12:50

① 如何实现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"

阅读全文

与android横向选择器相关的资料

热点内容
php中怎么注释 浏览:992
adxl345与单片机 浏览:279
服务器世界第一是什么公司的 浏览:19
精通编程入门 浏览:16
99单片机原理 浏览:61
linuxssh互信 浏览:288
支持128加密的浏览器 浏览:292
程序员下载器 浏览:48
退出云服务器代码 浏览:900
军状如命令 浏览:263
如何安卓系统更新 浏览:74
linux命令在哪里输入 浏览:497
编程语言集合类怎么选 浏览:93
如何将pdf转化为word 浏览:11
迈克菲隔离区解压密码 浏览:785
怎么用伟福编译 浏览:867
计算机算法专家 浏览:501
什么app清理垃圾 浏览:643
android流媒体服务器 浏览:183
各种算法的时间复杂度是指 浏览:116