2016-07-26 31 views
0

這是原來的佈局:http://prntscr.com/bxods5一個按鈕後,佈局的順序變化變得不可見

它的XML:

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

    > 
    <TableRow 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:weightSum="10"> 

     <Button 
      android:id="@+id/editBtn" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="0dp" 
      android:layout_height="36dp" 
      android:layout_column="2" 
      android:layout_weight="2" 
      android:onClick="editEvent" 
      android:text="EDIT" /> 

     <TextView 
      android:id="@+id/attendingEventInListviewRow" 
      android:layout_width="0dp" 
      android:layout_weight="6" 
      android:layout_height="wrap_content" 
      android:layout_column="38" 
      android:height="30sp" 
      android:tag="Events2goName" 
      android:text="Events2go" 
      android:textColor="#000000" 
      android:textSize="22sp" 
      android:textStyle="normal" 
      android:layout_gravity="right" 
      /> 

     <Button 
      android:id="@+id/cancel_arrive" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="0dp" 
      android:layout_weight="2" 
      android:layout_height="36dp" 
      android:layout_column="37" 
      android:layout_gravity="right" 
      android:onClick="selectCancelArrive" 
      android:text="Nope" /> 
    </TableRow> 



</TableLayout> 

的問題是,不是所有的用戶都可以編輯,所以對於一些用戶的「編輯」按鈕消失,就像這樣:

if(resource==R.layout.attending_listview_row) { 
     eventName = (TextView) view.findViewById(R.id.attendingEventInListviewRow); 
     cancelArrive = (Button) view.findViewById(R.id.cancel_arrive); 
     editBtn=(Button)view.findViewById(R.id.editBtn); 
     editBtn.setVisibility(View.GONE); 
    } 
    if (myEvent != null) { 
     if (myEvent.getOwner()== LocalDataBase.getCurrentUser()) { 
     editBtn.setVisibility(View.VISIBLE); 

     } 

我仍然希望「不」按鈕,Events2Go文本視圖留在自己的地方afrer,但究竟是什麼發生,我s這個:http://prntscr.com/bxoggo

什麼是最好的方法,讓他們堅持自己的位置?


編輯:

現在我知道這個問題是 「水漲船高」 和 「看不見」 之間的區別。

回答

3

我覺得現在你都躲在editBtn這樣

editBtn.setVisibility(View.GONE);

此更改

editBtn.setVisibility(View.INVISIBLE);

讓我知道是它工作與否,如果不將檢查

0

使用RelativeLayout的。嘗試

<RelativeLayout   
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_toLeftOf="@+id/cancel_arrive" 
     android:orientation="horizontal"> 

     <Button 
      android:id="@+id/editBtn" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="wrap_content" 
      android:layout_height="36dp" 
      android:onClick="editEvent" 
      android:text="EDIT" /> 

     <TextView 
      android:id="@+id/attendingEventInListviewRow" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:height="30sp" 
      android:tag="Events2goName" 
      android:text="Events2go" 
      android:textColor="#000000" 
      android:textSize="22sp" 
      android:textStyle="normal" 
      android:layout_gravity="right" 
      /> 

    </LinearLayout> 

    <Button 
     android:id="@+id/cancel_arrive" 
     style="?android:attr/buttonStyleSmall" 
     android:layout_width="wrap_content" 
     android:layout_height="36dp" 
     android:layout_alignParentRight="true" 
     android:onClick="selectCancelArrive" 
     android:text="Nope" /> 

</RelativeLayout>