這是一個android開發問題。
如果我首先使用setContentView(R.layout.main);
將內容視圖設置爲我的xml佈局,然後使用addContentView(layout, params)
添加另一個內容視圖,則內容視圖會相互重疊。我希望第二個內容視圖直接在第一個視圖下定位。是否有可能或者我需要以某種方式結合xml和編程創建的佈局?兩種佈局都是線性的。彼此之間的佈局
在此先感謝
這是一個android開發問題。
如果我首先使用setContentView(R.layout.main);
將內容視圖設置爲我的xml佈局,然後使用addContentView(layout, params)
添加另一個內容視圖,則內容視圖會相互重疊。我希望第二個內容視圖直接在第一個視圖下定位。是否有可能或者我需要以某種方式結合xml和編程創建的佈局?兩種佈局都是線性的。彼此之間的佈局
在此先感謝
把一個LinearLayout
內部佈局都與垂直方向。而已。
編輯:
我的意思是,你必須創建一個3佈局的XML文件。
主佈局文件,建議立即進行刪除是這樣的:
<LinearLayout android:orientation="vertical">
<include android:id="+id/lay1" android:layout="@layout/layout1"/>
<include android:id="+id/lay2" android:layout="@layout/layout2"/>
</LinearLayout>
現在您的主要佈局到您的setContentView(R.layout.main)
謝謝你們。我很欣賞這些反饋。
無法使父佈局(CoordinatorLayout)上的方向垂直。
雖然將兩個元素都放在垂直方向的LinearLayout中,
上面的一條評論說我應該首先製作一個appbarlayout:是的,我改變了它。我已將其更改爲LinearLayout,作爲我嘗試讓項目停止彼此繪製的一種嘗試。
我不確定這是解決這個問題的正確方法,但它工作。我會繼續前進。再次感謝。
要放在對方(一個頂部下除外)頂部的佈局,這就是我所做的:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/topLayout"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_alignParentTop="true"
android:background="@color/colorAccent">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="126dp"
android:text="Existing Client"
android:textColor="@android:color/white"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="@color/colorPrimary">
<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="138dp"
android:text="New Client"
android:textColor="@android:color/white"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
而結果:
我的意圖是使用佈局作爲填充屏幕的一定寬度的按鈕。
對不起,讓您煩惱,但是如何將xml佈局轉換爲LinearLayout呢? – 2010-09-21 09:42:42
@Mountain King:你必須使用'include'標籤。我在我的帖子中做了一個修改。查看。 – Praveen 2010-09-21 10:18:35