Cześć.
Mam problem z linear layoutem. Tzn. chce dodać dwa przyciski w kodzie w linear layoucie w orientacji poziomej. Wszystko jest ok, ale kolejnym krokiem jaki chce zrobić to przesunąć drugi przycisk tak aby jego część była schowana pod pierwszym. Wszystko mi się udaje prócz sprawienia aby przesunięta część drugiego przycisku była pod pierwszym przyciskiem.
Oto kod:
public class MainActivity extends Activity {
Button buttonFirst, buttonSecond;
LinearLayout lau;
LayoutParams params;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonFirst = new Button(getApplicationContext());
buttonSecond = new Button(getApplicationContext());
lau = (LinearLayout) findViewById(R.id.layoutmadafaka);
params = new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(-30, 0, 0, 0);
buttonSecond.setLayoutParams(lp);
buttonSecond.setBackgroundColor(Color.BLACK);
lau.addView(buttonFirst,params);
lau.addView(buttonSecond);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
oraz xml
<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"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello_world" />
<LinearLayout
android:id="@+id/layoutmadafaka"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:orientation="horizontal" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="-30dp"
android:text="Button"
android:background="#000000"/>
</LinearLayout>
</RelativeLayout>
Drugi przycisk jest przesuwany, lecz jego przesunięta część jest nad przyciskiem pierwszym. Ja chce żeby ta przesunięta część drugiego przycisku była pod pierwszym przyciskiem. Jak mogę to zrobić w kodzie? Jakich zmian potrzebuje? Zaznaczam, że musze to zrobić w kodzie i nie mogę dodać w xmlu i dac im status gone lub invisible. Da się to zrobić?