【发布时间】:2016-06-05 19:45:51
【问题描述】:
我有一个由两个子线性布局组成的框架布局(一个在另一个之上) 我有两个按钮“1”和“2” 当我按 1 时,我希望第一个线性布局位于第二个线性布局之上
当我按 2 时,我希望第二个线性布局位于第一个线性布局之上
我使用了 bringToFront() 来执行此操作 但是什么也没发生
我的布局
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="horizontal"
android:gravity="center">
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/button1"
android:text="1"/>
<Button
android:layout_height="wrap_content"
android:text="2"
android:layout_width="wrap_content"
android:id="@+id/button2"/>
</LinearLayout>
<FrameLayout
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_weight="1">
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="horizontal"
android:background="#D88681"
android:id="@+id/firstLayout"/>
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="horizontal"
android:background="#57E8A7"
android:id="@+id/secondLayout"/>
</FrameLayout>
我的主要活动
public class MainActivity extends Activity
{
LinearLayout first, second;
Button btn1, btn2;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
first = (LinearLayout) findViewById(R.id.firstLayout);
second = (LinearLayout) findViewById(R.id.secondLayout);
Button btn1 = (Button) findViewById(R.id.button1);
btn1.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View p1)
{
first.bringToFront();
}
});
btn2 = (Button) findViewById(R.id.button2);
btn2.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View p1)
{
second.bringToFront();
}
});
}
}
【问题讨论】:
标签: android android-framelayout