1
我使用此代碼移動和相對佈局調整按鈕...
計劃當我觸摸屏幕時崩潰,可能是什麼原因。?
ViewGroup relativeL;
onCreate(){
relativeL = (ViewGroup) findViewById(R.id.relativeLayout);
relativeL.setOnTouchListener(new RelativeLayout.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
methodMove();
return true;
}
});
}
public void methodMove(){
View button = findViewById(R.id.helloButton);
TransitionManager.beginDelayedTransition(relativeL);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
relativeL.setLayoutParams(layoutParams);
button.setLayoutParams(new RelativeLayout.LayoutParams(130,250));
}
我已經嘗試使RelativeLayout類型而不是ViewGroup的相對佈局,仍然沒有工作。指導,...預先感謝您..
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="my context"
android:id="@+id/relativeLayout">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:id="@+id/helloButton"/>
嘗試更改爲FrameLayout.LayoutParams –
nope..doesnt work .. –
什麼是hello的父佈局按鈕 –