Sto usando questo codice per spostare e ridimensionare il pulsante in un layout relativo ...
Il programma si arresta in modo anomalo quando tocco lo schermo, quale può essere la ragione.
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));
}
Ho provato a fare il layout relativo solo come tipo RelativeLayout invece di ViewGroup, ma non ha ancora funzionato. Guida, ... grazie in anticipo ..
<?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"/>
risposte:
0 per risposta № 1Sono mobile e non riesco a controllare il codice ma potresti provare a cambiare
button.setLayoutParams(new RelativeLayout.LayoutParams(130,250));
A
button.setLayoutParams(new FrameLayout.LayoutParams(130,250));