【问题标题】:Disable auto expand of edittext when typing键入时禁用edittext的自动扩展
【发布时间】:2018-12-04 07:49:38
【问题描述】:

我的活动有:1 个 youtubePlayerView,下面有 1 个编辑文本。 当我在编辑文本中输入超过 4 行时,我的 youtube 视频意外停止。 我认为原因是 youtubePlayer 布局之上的其他布局,使 youtube 视频停止。

这是 LogCat: W/YouTubeAndroidPlayerAPI:YouTube 视频播放因播放器顶部未经授权的覆盖而停止。 YouTubePlayerView 被 android.view.View 遮挡 任何人都有编辑扩展问题的解决方案。

这是我在手机上录制的链接 youtube 视频,用于演示此错误: https://youtu.be/zE8vzmaT0-Q

这是我用于该活动的 xml

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

<com.google.android.youtube.player.YouTubePlayerView
    android:id="@+id/youtubeView"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="4"></com.google.android.youtube.player.YouTubePlayerView>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1.5"
    android:background="#1d75a1"
    android:elevation="18dp"
    android:orientation="horizontal"
    android:padding="1.5dp"
    android:weightSum="16">

    <ImageButton
        android:id="@+id/btPreviousTrack"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_marginLeft="5dp"
        android:layout_weight="2.5"
        android:background="#bdf6f9"
        android:src="@drawable/previous_track" />

    <Spinner
        android:id="@+id/spinnerSelectTrack"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="2.5"></Spinner>

    <ImageButton
        android:id="@+id/btNextTrack"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="2.5"
        android:background="#bdf6f9"
        android:src="@drawable/next_track" />

    <ImageButton
        android:id="@+id/btCheck"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_gravity="end"
        android:layout_marginLeft="5dp"
        android:layout_weight="8.5"
        android:background="#bdf6f9"
        android:src="@drawable/check_green_mark" />
</LinearLayout>

<EditText
    android:id="@+id/etAnswer"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="3.5"
    android:background="#5abce6"
    android:elevation="15dp"
    android:ems="10"
    android:gravity="start"
    android:hint="type answer here"
    android:inputType="textMultiLine"
    android:textSize="24sp"
    android:lines="5"
    android:maxLines="5"/>

<TextView
    android:id="@+id/tvResult"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="4"
    android:background="#8edaf1"
    android:elevation="1dp"
    android:textSize="24sp" />

【问题讨论】:

  • 尝试将 maxHeight 赋予您的 editText,这将避免在给定高度之后扩展您的 EditText。
  • 谢谢,但是edittext还是会展开,没什么不同

标签: android android-youtube-api


【解决方案1】:

要解决这个问题,请将此代码添加到您的 EditText

android:layout_width="0dp"
android:layout_weight="1"

【讨论】:

  • 感谢您的评论,但我使用 layout_weight 来显示 layout_height,因此将 layout_weight 设置为 1 显示使得 edittext 区域如此之小
【解决方案2】:

感谢大家的帮助, 我已经用另一种方式解决了这个问题。

在 onCreated() 中添加以下代码,以在键盘出现时调整所有视图的大小,这样键盘布局就不会超过 youtubePlayerView 布局,那么视频就不会停止。

this.getWindow().setSoftInputMode(
            WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE|WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-09
    • 1970-01-01
    • 1970-01-01
    • 2018-03-20
    • 1970-01-01
    • 2012-05-07
    • 1970-01-01
    相关资源
    最近更新 更多