默认情况下,在我当前的布局中,顶部有两个TextView,底部有一个ImageView。我想通过将ImageView放在顶部并使用Java将TextView放在底部来改变这一点。请帮忙。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="2" >
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:weightSum="2" >
<TextView
android:id="@+id/tvText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/text_view"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textSize="13dp"
android:textStyle="bold" />
<TextView
android:id="@+id/tvText2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_weight="1"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:background="@drawable/text_view"
android:textSize="13dp"
android:textStyle="bold"
/>
</LinearLayout>
</FrameLayout>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/ivImage"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="@drawable/text_view"
android:scaleType="fitXY" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
答案 0 :(得分:1)
这就是我所做的:我在xml中增加了2个帧布局 当你点击第一个文本视图时,它将改变视图我的意思是 在框架布局之上,将显示下两个。希望这有助于你
public class MainActivity extends Activity
{
LinearLayout ll;
TextView tv;
FrameLayout ff2, ff1, ff3, ff4;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ff1 = (FrameLayout) findViewById(R.id.lay1);
ff2 = (FrameLayout) findViewById(R.id.lay2);
ff3 = (FrameLayout) findViewById(R.id.lay3);
ff4 = (FrameLayout) findViewById(R.id.lay4);
ff3.setVisibility(View.GONE);
ff4.setVisibility(View.GONE);
tv = (TextView) findViewById(R.id.tvText);
tv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
ff1.setVisibility(View.GONE);
ff2.setVisibility(View.GONE);
ff3.setVisibility(View.VISIBLE);
ff4.setVisibility(View.VISIBLE);
Toast.makeText(getApplicationContext(), "layout change",
Toast.LENGTH_LONG).show();
}
});
}
}
这是布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="2" >
<FrameLayout
android:id="@+id/lay1"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:weightSum="2" >
<TextView
android:id="@+id/tvText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/weed2"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textSize="13dp"
android:textStyle="bold" />
<TextView
android:id="@+id/tvText2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/weed2"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textSize="13dp"
android:textStyle="bold" />
</LinearLayout>
</FrameLayout>
<FrameLayout
android:id="@+id/lay2"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/ivImage"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="@drawable/ic_launcher"
android:scaleType="fitXY" />
</LinearLayout>
</FrameLayout>
<FrameLayout
android:id="@+id/lay3"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/ivImage"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="@drawable/ic_launcher"
android:scaleType="fitXY" />
</LinearLayout>
</FrameLayout>
<FrameLayout
android:id="@+id/lay4"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:weightSum="2" >
<TextView
android:id="@+id/tvText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/weed2"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textSize="13dp"
android:textStyle="bold" />
<TextView
android:id="@+id/tvText2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/weed2"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textSize="13dp"
android:textStyle="bold" />
</LinearLayout>
</FrameLayout>
</LinearLayout>