如何制作ImageView比例尺以在其下方留出空间以放置控件?

问题描述

| 因此,我正在编写用于图像处理的该应用程序,当用户从图库中选择图像后,我将在选项页面中顶部具有多个控件,并在中间显示所选图像的预览。底部还有一个“开始”按钮,但是如果图像足够高,该按钮将被遮盖。 我考虑过将图像调整为可以正常工作的特定高度,但是该高度会在不同设备上发生变化。理想情况下,我希望图像在控件和按钮之间占据尽可能多的空间,但我不知道该怎么做。我尝试使用垂直布局,但这没什么区别。 在此图像中,仿真器窗口在右侧。 这是我的XML。有点混乱,但是这里:
 <?xml version=\"1.0\" encoding=\"utf-8\"?>

 <LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"
android:id=\"@+id/linearLayout\" android:orientation=\"vertical\"
android:layout_height=\"wrap_content\" android:padding=\"10px\"
android:layout_width=\"fill_parent\">
<TextView android:textSize=\"18px\" android:text=\"GIF Options\"
    android:id=\"@+id/textView3\" android:layout_width=\"wrap_content\"
    android:layout_height=\"wrap_content\">
</TextView>

<TableLayout android:id=\"@+id/tableLayout\"
    android:layout_width=\"fill_parent\" android:layout_height=\"wrap_content\"
    android:stretchColumns=\"1\">

    <TableRow>
        <TextView android:layout_height=\"wrap_content\" android:text=\"FPS:\"
            android:id=\"@+id/TextView1\"     android:layout_width=\"wrap_content\"
            android:enabled=\"false\" android:textSize=\"17px\"></TextView>
        <EditText android:text=\"20\" android:inputType=\"numberDecimal\"
            android:id=\"@+id/EditTextFPS\" android:numeric=\"decimal\"
            android:singleLine=\"true\" android:layout_height=\"wrap_content\"
            android:layout_width=\"wrap_content\" android:digits=\"2\"
            android:width=\"50px\"></EditText>
    </TableRow>
    <TableRow>
        <TextView android:layout_height=\"wrap_content\" android:text=\"Frames:\"
            android:id=\"@+id/TextView2\" android:layout_width=\"wrap_content\"
            android:enabled=\"false\" android:textSize=\"17px\"></TextView>

        <EditText android:layout_width=\"wrap_content\"
            android:layout_height=\"wrap_content\" android:text=\"70\"
            android:inputType=\"numberDecimal\" android:id=\"@+id/EditTextFrames\"
            android:numeric=\"decimal\" android:singleLine=\"true\" android:digits=\"2\"></EditText>
    </TableRow>
    <TableRow>
        <TextView android:layout_height=\"wrap_content\" android:text=\"Saturation Boost: \"
            android:id=\"@+id/TextView2\" android:layout_width=\"wrap_content\"
            android:enabled=\"false\" android:textSize=\"17px\"></TextView>

        <SeekBar android:layout_height=\"wrap_content\"
            android:layout_width=\"fill_parent\" android:id=\"@+id/seekBar1\"
            android:layout_alignParentLeft=\"true\" android:max=\"10\"></SeekBar>

    </TableRow>
</TableLayout>

<TextView android:layout_width=\"wrap_content\"
    android:layout_height=\"wrap_content\" android:id=\"@+id/textView4\"
    android:layout_gravity=\"center\" android:text=\"Chosen Image\"
    android:textSize=\"16px\"></TextView>
<ImageView android:layout_width=\"wrap_content\" android:src=\"@drawable/icon\"
    android:layout_gravity=\"center\" android:id=\"@+id/optionspreview\"
    android:isScrollContainer=\"true\" android:layout_height=\"fill_parent\"></ImageView>

<Button android:layout_height=\"wrap_content\"
    android:layout_width=\"wrap_content\" android:textSize=\"22px\"
    android:id=\"@+id/startbutton\" android:text=\"Start!\"
    android:layout_alignParentBottom=\"true\"
    android:layout_centerHorizontal=\"true\" android:layout_gravity=\"center\"></Button>

 </LinearLayout>
    

解决方法

您可以通过使用RelativeLayout来实现。 过于简单的答案(因为我不知道您的布局)是将所有顶部控件都放在一个布局内(例如layoutTop),所有按钮控件都放在一个布局内(layoutBottom),而ImageView放在中间:
<RelativeLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"
   android:id=\"@+id/layoutWrapper\" 
   android:layout_width=\"fill_parent\" 
   android:layout_height=\"fill_parent\"
   >

   <LinearLayout
      android:id=\"@+id/layoutTop\" 
      android:layout_width=\"fill_parent\" 
      android:layout_height=\"wrap_content\" 
      android:layout_alignParentTop=\"true\"
   >
      <TextView 
         android:layout_width=\"wrap_content\" 
         android:layout_height=\"wrap_content\" 
         android:text=\"Sparta!!!\"
      />
   </LinearLayout>

   <ImageView
       android:layout_width=\"wrap_content\" 
       android:layout_height=\"wrap_content\" 
       android:layout_below=\"@id/layoutTop\"
       android:layout_above=\"@+id/layoutBottom\"
       android:src=\"@drawable/empty_star\" 
   />

   <LinearLayout
      android:id=\"@id/layoutBottom\" 
      android:layout_width=\"fill_parent\" 
      android:layout_height=\"wrap_content\" 
      android:layout_alignParentBottom=\"true\"
  >
      <TextView 
         android:layout_width=\"wrap_content\" 
         android:layout_height=\"wrap_content\" 
         android:text=\"Sparta!!!\"
      />
  </LinearLayout>

</RelativeLayout>
这里的窍门是注意我如何创建layoutBottom的ID。我声明实际布局时不会写\“ + \”,而是第一次使用它,即在ImageView中。     ,发布您的(XML)布局。您最有可能使用
LinearLayout
RelativeLayout
将简化此过程。如果您发布XML,我将助您一臂之力。 编辑:我会大大简化您的布局。这种布局非常复杂,并且需要大量内存和处理才能膨胀。您可以使用相对布局的一个父级轻松创建此布局。键为
android:layout_alignParentBottom
以正确放置。     

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...