在framelayout旁边放置按钮

时间:2014-11-28 12:41:25

标签: android

我尝试了以下内容:

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

<FrameLayout
    android:id="@+id/recipe_fragment_camera_preview"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/recipe_fragment_imageview_pattern"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:contentDescription="@string/imageview_description" />

</FrameLayout>

<Button
    android:id="@+id/recipe_fragment_button_take_photo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/button_take_photo" />

不幸的是,这不起作用。 FrameLayout正在隐藏按钮,因为FrameLayout正在占据整个屏幕。我想在FrameLayout旁边有一个按钮。我怎么能实现这个目标?

4 个答案:

答案 0 :(得分:2)

尝试这样,

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

<FrameLayout
    android:id="@+id/recipe_fragment_camera_preview"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/recipe_fragment_imageview_pattern"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:contentDescription="@string/imageview_description" />

</FrameLayout>

<Button
    android:id="@+id/recipe_fragment_button_take_photo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/button_take_photo" />

答案 1 :(得分:1)

在frameLayout和Button中添加:

android:layout_weight = "2"

答案 2 :(得分:1)

只需在FrameLayout中添加权重

<FrameLayout android:layout_weight="1"
android:id="@+id/recipe_fragment_camera_preview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal" >

答案 3 :(得分:1)

试试这个

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

   <FrameLayout
     android:id="@+id/recipe_fragment_camera_preview"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignParentTop="true"
     android:layout_above="@recipe_fragment_button_take_photo"
     android:orientation="horizontal" >

    <ImageView
      android:id="@+id/recipe_fragment_imageview_pattern"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:contentDescription="@string/imageview_description" />

  </FrameLayout>

  <Button
    android:id="@+id/recipe_fragment_button_take_photo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:text="@string/button_take_photo" />

</RelativeLayout>