2016-07-17 34 views
0

這裏的問題是我試圖將textview粘貼到底部使用「alignParentBottom = true」,但它隱藏了textview。以下是佈局xml文件:alignParentBottom隱藏textview

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 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"> 

<Switch 
    android:onClick="adjustFocus" 
    android:layout_margin="10dp" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hhmm" 
    android:id="@+id/hhmm" 
    android:checked="false" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentEnd="true" /> 

<Switch 
    android:onClick="adjustFocus" 
    android:layout_margin="10dp" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hr12" 
    android:id="@+id/hr12" 
    android:checked="false" 
    android:layout_below="@+id/hhmm" /> 

<Switch 
    android:onClick="adjustFocus" 
    android:layout_margin="10dp" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hr24" 
    android:id="@+id/hr24" 
    android:checked="false" 
    android:layout_below="@+id/hr12" /> 
<Switch 
    android:onClick="adjustFocus" 
    android:layout_margin="10dp" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hh_double" 
    android:id="@+id/hhdbl" 
    android:checked="false" 
    android:layout_below="@+id/hr24" /> 
<Switch 
    android:onClick="adjustFocus" 
    android:layout_margin="10dp" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/mm_double" 
    android:id="@+id/mmdbl" 
    android:checked="false" 
    android:layout_below="@+id/hhdbl" /> 



<TextView 
    android:textColor="@color/black" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceSmall" 
    android:text="@string/offset" 
    android:id="@+id/textView2" 
    android:layout_below="@+id/mmdbl" 
    android:layout_margin="10dp" /> 


//below is the textview I'm trying to stick to the bottom 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:text="Large Text" 
     android:id="@+id/textView3" 
     android:background="@color/black" 
     android:textColor="@color/white" 
     android:layout_alignParentBottom="true" 
/> 
</RelativeLayout> 

以下是與上述佈局xml文件關聯的java代碼。這是一個片段...

public class myfrag extends Fragment { 
TextView tv; 
@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
View v = inflater.inflate(R.layout.my_fragment, container, false); 
tv = (TextView)v.findViewById(R.id.textView3); 


return v; 
} 

} 

請幫我,我錯了。

+1

可以顯示的截圖? – Ironman

+0

textview在預覽中可見,但在真實設備上測試時隱藏。以下是屏幕截圖...預覽:http://i.imgur.com/E6F5RnP.png ...在真實設備上:http: //i.imgur.com/SBNEZ06.png ...請檢查他們兩個 –

+0

所以,你對TextView以編程方式實時執行的操作是什麼? –

回答

0

更新這個TextView的:

<TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:text="Large Text" 
     android:id="@+id/textView3" 
     android:background="#111111" 
     android:textColor="@color/white" 
     android:layout_alignParentBottom="true" 
     android:layout_below="@+id/textView2" 
     android:gravity="center|bottom" />