android 软键盘 下一个,使设备的顶部和软键盘之间出现一个编辑文本android

就拿我的代码作为例子给你,你可以这样做以下: 让XML为:

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical" >

android:id="@+id/scrlv"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:layout_centerHorizontal="true"

android:layout_centerVertical="true"

android:background="#123789" >

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:background="#1188ff" >

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:layout_below="@+id/headerlayout"

android:background="#456789" >

android:id="@+id/etemail"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_marginLeft="20dp"

android:layout_marginRight="20dp"

android:layout_marginTop="40dp"

android:hint="Text 1"

android:maxLines="3" />

android:id="@+id/etpassword"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_alignLeft="@+id/etemail"

android:layout_alignRight="@+id/etemail"

android:layout_below="@+id/etemail"

android:hint="Text 2"

android:inputType="textPassword"

android:maxLines="3" />

android:id="@+id/etusername"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_alignLeft="@+id/etemail"

android:layout_alignRight="@+id/etemail"

android:layout_below="@+id/etpassword"

android:hint="Text 3"

android:maxLines="3" />

android:id="@+id/etphone"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_alignLeft="@+id/etemail"

android:layout_alignRight="@+id/etemail"

android:layout_below="@+id/etusername"

android:hint="Text 4"

android:inputType="text"

android:maxLines="5" />

android:id="@+id/chkterms"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignLeft="@+id/etemail"

android:layout_alignRight="@+id/etemail"

android:layout_below="@+id/etphone"

android:layout_marginTop="10dp"

android:text="Conditions Aplly"

android:textColor="@android:color/black" />

android:id="@+id/btnlogin"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@+id/chkterms"

android:layout_centerHorizontal="true"

android:layout_marginTop="10dp"

android:text="Login" />

然后代码:

[1]获取设备的屏幕分辨率:高度,宽度

[2]把你的EditText的onFocusChange

[3],如果您EditText获得焦点然后

[4]获取EditText的底部,如果底部大于(ScreenHeight/3),则

[5]将Your_ScrollView滚动到(left,(ScreenHeight/3));

public class MainActivity extends Activity implements OnClickListener{

private EditText etEmail, etPassword, etUserName, etPhoneNo;

private CheckBox chkTerms;

private Button btnLogin;

ScrollView scrlv;

int sw, sh, left, bottom;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

scrlv = (ScrollView) findViewById(R.id.scrlv);

etEmail = (EditText) findViewById(R.id.etemail);

etPassword = (EditText) findViewById(R.id.etpassword);

etUserName = (EditText) findViewById(R.id.etusername);

etPhoneNo = (EditText) findViewById(R.id.etphone);

DisplayMetrics dm = new DisplayMetrics();

getWindowManager().getDefaultDisplay().getMetrics(dm);

sw = dm.widthPixels;

sh = dm.heightPixels;

System.out.println("Screen Width = " + sw);

System.out.println("Screen Height = " + sh);

chkTerms = (CheckBox) findViewById(R.id.chkterms);

btnLogin = (Button) findViewById(R.id.btnlogin);

btnLogin.setOnClickListener(this);

etUserName.setOnFocusChangeListener(new OnFocusChangeListener() {

@Override

public void onFocusChange(View v, boolean hasFocus) {

if(etUserName.hasFocus()) {

left = etUserName.getLeft();

bottom = etUserName.getTop();

if (bottom > sh/3) {

System.out.println("Umn Left :: " + left);

System.out.println("Umn Bottom :: " + bottom);

scrlv.scrollTo(left, (sh/3));

left = etUserName.getLeft();

bottom = etUserName.getTop();

System.out.println("Umn Left :: " + left);

System.out.println("Unm Bottom :: " + bottom);

}

}

}

});

etPhoneNo.setOnFocusChangeListener(new OnFocusChangeListener() {

@Override

public void onFocusChange(View v, boolean hasFocus) {

if(etPhoneNo.hasFocus()) {

left = etPhoneNo.getLeft();

bottom = etPhoneNo.getTop();

if (bottom > sh/3) {

System.out.println("Phno Left :: " + left);

System.out.println("Phno Bottom :: " + bottom);

scrlv.scrollTo(0, (sh/3));

left = etPhoneNo.getLeft();

bottom = etPhoneNo.getTop();

System.out.println("Phno Left :: " + left);

System.out.println("Phno Bottom :: " + bottom);

}

}

}

});

}

@Override

public void onClick(View v) {

// TODO Auto-generated method stub

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值