【问题标题】:Android LinearLayout with Button and FrameLayout using the Maximum HeightAndroid LinearLayout with Button 和 FrameLayout 使用最大高度
【发布时间】:2014-04-28 18:37:54
【问题描述】:

我正在尝试创建一个layout,其中有一个LinearLayout,在其中我想要一个FrameLayout 和一个button。

我希望button 使用linearlayout 的底部并使用按钮的最大宽度和足够的高度,使用换行内容。

另一个组件,FrameLayout 我想在屏幕的剩余部分使用它。

我该怎么做?

到目前为止的布局..

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

      android:layout_width="wrap_content"
      android:layout_height="match_parent"

      android:orientation="vertical" >

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

         <Button
            android:id="@+id/button_capture"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:onClick="snapIt"
            android:text="@string/Capture" />

</LinearLayout>

没有显示按钮:s

提前非常感谢;)

【问题讨论】:

    标签: android button height android-linearlayout android-framelayout


    【解决方案1】:

    最好使用与父底部对齐的按钮的相对布局以及其上方的框架布局占据屏幕的其余空间。像这样

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="match_parent" >
    
    <FrameLayout
        android:id="@+id/camera_preview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:layout_above="@+id/button_capture"/>
    
    <Button
        android:id="@+id/button_capture"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:onClick="snapIt" 
        android:layout_alignParentBottom="true"/>
    
    </RelativeLayout>
    

    【讨论】:

    • 成功了,对!我忘记了RelativeLayout :s 非常感谢老兄;)
    【解决方案2】:

    使用下面的xml

    <?xml version="1.0" encoding="utf-8"?>
        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    
              android:layout_width="wrap_content"
              android:layout_height="match_parent"
    
              android:orientation="vertical" >
    
    
    
                 <Button
                    android:id="@+id/button_capture"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:onClick="snapIt"
                    android:layout_alignParentBottom="true"
                    android:text="capture" />
         <FrameLayout
                    android:id="@+id/camera_preview"
                    android:layout_width="fill_parent"
                    android:layout_height="match_parent"
                    android:layout_above="@+id/button_capture"
                     />
        </RelativeLayout>
    

    【讨论】:

      【解决方案3】:

      我只是想制作这些布局,在比较我的布局代码和你的布局代码后,我发现了一个不同的代码,在我的代码中有。您是否遗漏了它或只是将其移开导致它在布局代码中无用?

      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:orientation="vertical" >
      
          <Button
              android:id="@+id/button1"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Button" />
      
          <FrameLayout
              android:id="@id/flayout"
              android:layout_width="match_parent"
              android:layout_height="wrap_content" 
              android:text="@string/hello_world">
         </FrameLayout>
      
      </LinearLayout>
      

      【讨论】:

      • 我不明白你的意思,你能解释一下吗?反正我的问题已经解决了
      猜你喜欢
      • 2016-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-30
      • 2013-09-23
      相关资源
      最近更新 更多