答案 0 :(得分:0)
RelativeLayout
将是最佳解决方案。您也可以使用LinearLayout
,但这需要一些不利于性能的嵌套。
答案 1 :(得分:0)
@约翰
你应该去RelativeLayout
显示RelativeLayout
1)在res/drawable
文件夹中,创建一个新文件background_border.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<!-- This is the stroke you want to define -->
<stroke android:width="1dp"
android:color="@android:color/black"/>
<solid android:color="@android:color/white" /> // inner color
</shape>
此drawable将用于设置布局周围的矩形边框
2)然后按如下所示创建布局
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">
<RelativeLayout
android:id="@+id/layoutOne"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/background_border"> //setting square border here
<TextView
android:id="@+id/lblDeposite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="Deposits">
<TextView
android:id="@+id/txtDepositeValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true" />
<TextView
android:id="@+id/lblShareCapital"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/lblDeposite"
android:text="Share Capital">
<TextView
android:id="@+id/lblAvailableBalance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Available Balance"
android:layout_below="@+id/txtDepositeValue"
android:layout_alignParentRight="true" />
</RelativeLayout>
//Similar to this layout create other two
<RelativeLayout
android:id="@+id/layoutTwo"
android:layout_below="@+id/layoutOne"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/background_border">
//Your code for inside content will go here just like the layoutOne add
all your views here but with different ids
</RelativeLayout>
<RelativeLayout
android:id="@+id/layoutThree"
android:layout_below="@+id/layoutTwo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/background_border">
//Your code for inside content will go here just like the layoutTwo add
all your views here but with different ids
</RelativeLayout>
</RelativeLayout> //Closing your parent view
3)现在,既然您希望可以在活动中点击所有视图,请为所有视图添加OnClickListener
layoutOne.setOnClickListener(this);
layoutTwo.setOnClickListener(this);
layoutThree.setOnClickListener(this);
然后覆盖onClick()
方法
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.layoutOne:
//your code for first view click
break;
case R.id.layoutTwo:
//your code for second view click
break;
case R.id.layoutThree:
//your code for third view click
break;
}