2016-08-31 122 views
0

在XML設計上我添加了兩個按鈕,其中一個按鈕的工作沒有任何問題,但第二個按鈕在設備上不可見。 (這兩個按鈕保留在XML中的ListView中)。如果有人能幫助我理解爲什麼會發生這種情況,我會很高興,我能否解決它。謝謝。Android按鈕在設備上不可見

XML(設置按鈕的問題是按鈕) -

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="gg.gg.MainActivity"> 


    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center_horizontal" 
     android:text="Tasks" 
     android:background="#e2e2e2" /> 

    <ListView 
     android:id="@+id/list_todo" 
     tools:listitem="@layout/item_todo" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"/> 

    <Button 
     android:layout_width="60dp" 
     android:layout_height="60dp" 
     android:src="@drawable/settings" 
     android:background="@drawable/settings" 
     android:onClick="ButtonClick" 
     android:id="@+id/settings" 
     android:layout_above="@+id/add_task" 
     android:layout_alignParentEnd="true" /> 

    <Button 
    android:layout_width="60dp" 
    android:layout_height="60dp" 
    android:id="@+id/add_task" 
    android:src="@drawable/addtask" 
    android:background="@drawable/addtask" 
    android:layout_alignParentBottom="true" 
    android:layout_alignEnd="@+id/settings" /> 

</RelativeLayout> 

+0

試着給你的代碼的元素提供所需的權重。 –

+0

我把你的XML粘貼到一個虛擬項目中(假設你沒有在繪圖中做任何奇怪的事情),它們都顯示在彼此之上。你在看什麼版本的Android? –

+0

@ChrisWard API 22 – proli2

回答

0

我想你想達到什麼是floationActionButton。嘗試了這一點:

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     tools:context="gg.gg.MainActivity"> 


     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center_horizontal" 
      android:layout_alignParentTop="true" 
      android:id="@+id/textview" 
      android:text="Tasks" 
      android:background="#e2e2e2" /> 

     <ListView 
      android:id="@+id/list_todo" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_below="@+id/textview" 
      /> 

     <android.support.design.widget.FloatingActionButton 
      android:id="@+id/fab" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom|end" 
      android:layout_margin="@dimen/fab_margin" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentRight="true" 
      android:src="@android:drawable/ic_dialog_email" /> 

     <android.support.design.widget.FloatingActionButton 
      android:id="@+id/fab1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom|end" 
      android:layout_margin="@dimen/fab_margin" 
      android:layout_above="@+id/fab" 
      android:layout_alignParentRight="true" 
      android:src="@android:drawable/ic_dialog_email" /> 
    </RelativeLayout> 
    </FrameLayout> 
+0

仍然是同樣的問題。 – proli2

+0

看我的編輯。試試吧。 – Nidhi

1

enter image description here您的佈局應該如下:

<?xml version="1.0" encoding="utf-8"?> 
     <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" > 

     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
         xmlns:tools="http://schemas.android.com/tools" 
         android:layout_width="match_parent" 
         android:layout_height="match_parent" 
         tools:context="gg.gg.MainActivity"> 


      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:gravity="center_horizontal" 
       android:layout_alignParentTop="true" 
       android:id="@+id/textview" 
       android:text="Tasks" 
       android:background="#e2e2e2" /> 

      <ListView 
       android:id="@+id/list_todo" 
       tools:listitem="@layout/item_todo" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_above="@+id/linearlayout" 
       android:layout_below="@+id/textview" 
       /> 

      <LinearLayout 
       android:id="@+id/linearlayout" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
       android:orientation="vertical" 
       > 
      <Button 
       android:layout_width="60dp" 
       android:layout_height="60dp" 
       android:src="@drawable/settings" 
       android:background="@drawable/settings" 
       android:onClick="ButtonClick" 
       android:id="@+id/settings" 

       /> 

      <Button 
       android:layout_width="60dp" 
       android:layout_height="60dp" 
       android:id="@+id/add_task" 
       android:src="@drawable/addtask" 
       android:background="@drawable/addtask" 

       /> 
      </LinearLayout> 
     </RelativeLayout> 
+0

對不起,但仍未解決問題。 – proli2

+0

@ proli2它工作正常,我也附上截圖。 – Rajendra

0

使用浮動操作按鈕這一點。

+0

什麼都沒有:( – proli2

+0

讓我給你發一個Layout。 –

+0

你想浮動按鈕還是簡單按鈕? –

0
<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:mapbox="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=".HomeActivity"> 

<include 
    android:id="@+id/toolbar" 
    layout="@layout/toolbar" /> 



<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_centerVertical="true" 
    android:orientation="vertical"> 

    <ImageView 
     android:id="@+id/parking" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginRight="6dp" 
     android:src="@mipmap/parking_locs" /> 

    <ImageView 
     android:id="@+id/roads" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginRight="6dp" 
     android:layout_marginTop="10dp" 
     android:src="@mipmap/before_park_car" /> 

</LinearLayout> 

<ImageView 
    android:id="@+id/compass" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentRight="true" 
    android:layout_margin="10dp" 
    android:src="@mipmap/button_my_location" /> 
</RelativeLayout> 
+0

試試這個添加按鈕。 –

相關問題