2017-06-04 19 views
0

我對整個Android Studio和全部都很陌生,但我很快就習慣了這一切。Android Studio中的分層對象

現在,這裏是我的問題:

我有我的兩個屏幕填充按鈕主要活動,我想在頂部的第一個按鈕的複選框。

我已經查看了所有的互聯網,但我找不到一個線索。

編輯:混亂與對象的順序不起作用。

這是我的XML代碼(我還沒有填寫功能,還):

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.ggblbl.example.MainActivity"> 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:layout_marginBottom="8dp" 
     android:layout_marginLeft="16dp" 
     android:layout_marginRight="16dp" 
     android:layout_marginTop="16dp" 
     android:text="@string/button_one" 
     app:layout_constraintBottom_toTopOf="@+id/guideline" 
     app:layout_constraintHorizontal_bias="0.0" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="parent" 
     app:layout_constraintVertical_bias="0.0" /> 

    <Button 
     android:id="@+id/button2" 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:layout_marginBottom="16dp" 
     android:layout_marginLeft="16dp" 
     android:layout_marginRight="16dp" 
     android:layout_marginTop="8dp" 
     android:text="@string/button_two" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintHorizontal_bias="0.0" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="@+id/guideline" 
     app:layout_constraintVertical_bias="0.0" /> 

    <android.support.constraint.Guideline 
     android:id="@+id/guideline" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     app:layout_constraintGuide_percent="0.5" /> 

    <CheckBox 
     android:id="@+id/checkBox" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:text="@string/checkbox" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintHorizontal_bias="0.0" 
     android:layout_marginRight="150dp" 
     android:layout_marginLeft="150dp" 
     android:layout_marginBottom="20dp" 
     app:layout_constraintBottom_toTopOf="@+id/guideline" /> 
</android.support.constraint.ConstraintLayout> 

PS:我不知道這是否會有所幫助,但我使用API​​ 15和Android 2.3工作室。 2。

編輯:我有這個 I've got this,

但我想這 But I want this

回答

0

我最終選擇放棄使用複選框,因爲我想這是更換上按鈕硬編碼在複選框背後的按鈕。

我發現,切換按鈕做什麼,我需要太多。 這一個是在按鈕前面。

0

我已刪除的利潤和非所需的代碼。試試下面的佈局

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout 
    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"> 


    <Button 
     android:id="@+id/button1" 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:layout_marginBottom="32dp" 
     android:text="Button 1" 
     app:layout_constraintTop_toTopOf="parent" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintBottom_toTopOf="@+id/button2" 
     /> 

    <CheckBox 
     android:id="@+id/checkBox" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:text="CheckBox" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/button1" 
     /> 

    <Button 
     android:id="@+id/button2" 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:text="Button 2" 
     app:layout_constraintTop_toBottomOf="@+id/button1" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" /> 


</android.support.constraint.ConstraintLayout> 

編輯:它看起來像在按鈕畫圖是不可能的。在已編輯的佈局中,button1的底部邊距等於複選框的高度。您可以平均分配這個高度按鈕1和按鈕2頂部利潤率的下邊緣在支持我的要求,你可以看到下面的佈局,它給你想要的東西。在這個例子中,我通過一個TextView

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout 
    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"> 


    <TextView 
     android:id="@+id/button1" 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:text="Button 1" 
     app:layout_constraintTop_toTopOf="parent" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     android:background="#ddd" 
     app:layout_constraintBottom_toTopOf="@+id/button2" 
     /> 

    <CheckBox 
     android:id="@+id/checkBox" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="CheckBox" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintBottom_toBottomOf="@+id/button1" 
     /> 

    <Button 
     android:id="@+id/button2" 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:text="Button 2" 
     app:layout_constraintTop_toBottomOf="@+id/button1" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" /> 


</android.support.constraint.ConstraintLayout> 
+0

這樣做的事情......但不是我想要發生的事情。 – ggblbl

+0

@ggblbl你想要什麼? –

+0

我已經在我的問題中添加了圖片。 – ggblbl