2016-11-09 73 views
0

如何將DatePicker居中? Layout_centerhorizo​​ntal不起作用,它將其對齊到左側。Android中心DatePicker不工作

這裏是我的代碼:

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 
<TextView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="" 
    android:id="@+id/txtTitulo" 
    android:textIsSelectable="true" 

    android:textStyle="normal|bold" 
    android:paddingLeft="22dp"/> 
<DatePicker 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 

    android:id="@+id/DatePicker1" 
    android:calendarViewShown="false" 
    android:layout_centerHorizontal="true" 
    > 
</DatePicker></LinearLayout> 
</ScrollView> 
+0

試試'android:layout_gravity =「center_horizo​​ntal」' –

+0

沒關係,非常感謝! –

回答

0

中的DatePicker的家長是一個LinearLayout中。因此,在DatePicker中設置

android:layout_gravity="center_horizontal"