Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/192.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 拉伸编辑文本以调整图像_Android_Android Layout - Fatal编程技术网

Android 拉伸编辑文本以调整图像

Android 拉伸编辑文本以调整图像,android,android-layout,Android,Android Layout,如何创建一个布局,使其始终存在EditText,并遵守以下三条规则: EditText视图: 如果不存在图像,则填充整个父级(在运行时,可见性将设置为View.GONE,在本例中为) 如果图像的高度高于其宽度,则填充父高度的50% 如果图像宽度大于其高度,则填充父对象的其余部分 当然,图像会被拉伸以适合父矩形最底部50%的内部,同时保留纵横比 试试这个: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/andr

如何创建一个布局,使其始终存在
EditText
,并遵守以下三条规则:

EditText
视图:

  • 如果不存在图像,则填充整个父级(在运行时,可见性将设置为
    View.GONE,在本例中为
  • 如果图像的高度高于其宽度,则填充父高度的50%
  • 如果图像宽度大于其高度,则填充父对象的其余部分
  • 当然,图像会被拉伸以适合父矩形最底部50%的内部,同时保留纵横比

    试试这个:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    
    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:ems="10" >
    </EditText>
    
    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:src="@drawable/ic_launcher"/>
    </LinearLayout>
    
    
    
    我不相信单用一个xml布局就可以做到这一点,但简单的方法是使用多个xml布局文件,根据图像的显示和纵横比进行膨胀。

    我是这样做的。生成的布局如下所示:

    
    
    这无法解决问题;至少,它不满足将图像拉伸到填充父高度底部50%的条件“您可以随时在运行时调整图像的大小,因为您可以获得屏幕的高度。下面是一个调整图像大小的示例:对不起,我很感谢您的努力,但这并不能回答问题。看见我请求您删除此答案以清理页面。谢谢
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    
        <EditText
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="blah" />
    
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:visibility="gone"
            android:src="@drawable/photo1" />
    
    </LinearLayout>