2013-02-20 15 views
0

У меня возникла проблема с размещением кнопок. Я разрабатываю приложение, в котором, когда приложение запускает камеру, открывается (настраивается). Я добавил две кнопки в макете, моя проблема в том, что я не могу настроить кнопки. Я хочу, чтобы кнопки, которые были помещены как кнопка захвата, были внизу в центре, а кнопка загрузки будет внизу справа. Я использую следующий код.Проблема с размещением кнопок в android

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

<FrameLayout 
android:id="@+id/camera_preview" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:layout_weight="1" 
> 

</FrameLayout> 
    <Button 
     android:id="@+id/button_upload" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="0dp" 
     android:text="Upload" 
     /> 

    <Button 
     android:id="@+id/button_capture" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="0dp" 
     android:text="Capture" /> 


</RelativeLayout> 

Я также пробовал использовать LinearLayout. Может ли кто-нибудь сказать мне, где я делаю ошибку? Спасибо заранее.

ответ

1

попробовать это ...

android:layout_centerHorizontal="true" 

в Button теге

+0

Это переместило кнопку в центр, отлично. и как бы я переместил кнопку вправо? Также почему я не могу просто перетащить кнопку и место, где бы я ни захотел? –

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

    <FrameLayout 
     android:id="@+id/camera_preview" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:layout_alignBottom="@+id/button_upload" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_weight="1" > 

    </FrameLayout> 

    <Button 
     android:id="@+id/button_upload" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true" 
     android:text="Upload" /> 

    <Button 
     android:id="@+id/button_capture" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_marginRight="55dp" 
     android:layout_toLeftOf="@+id/button_upload" 
     android:text="Capture" /> 

</RelativeLayout>`enter code here` 
+0

попробуйте этот ... Я думаю, что это тот, который вам нужен ... –

+0

why marginRight 55dp? Это сработало. Можете ли вы объяснить, какие ошибки я делал, чтобы я мог избежать следующего раза. Также почему я не могу просто задрапировать и поместить кнопку, где бы я ни захотел с помощью мыши? –

+0

Я только что изменил ширину Framlayout от заполнения родительского контура, чтобы обернуть содержимое ... И затем установите маркер из кнопки Upload ... –

0

Так что я понял, это может быть сделано, как это.

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_marginBottom="0dp" 
    android:background="#A9A9A9" 
    android:orientation="vertical" > 

    <FrameLayout 
     android:id="@+id/camera_preview" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:layout_above="@+id/button_capture" 
    /> 
    <Button 
     android:id="@+id/button_capture" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     android:text="Capture" /> 

    <Button 
     android:id="@+id/button_upload" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentBottom="true" 
     android:text="Upload" /> 

    </RelativeLayout> 
Смежные вопросы