情景是这样:Dialog里面EditText弹出软键盘,结果主界面里面的两个TextView居然莫名其妙的下移了。
引起错乱的布局如下
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="3dp">
<TextView
android:id="@+id/t_blue"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_margin="3dp"
android:layout_weight="1"
android:background="@drawable/round_grey"
android:gravity="center"
android:text="蓝牙连接"
android:textSize="12dp" />
<TextView
android:id="@+id/t_plc"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_margin="3dp"
android:layout_weight="1"
android:background="@drawable/round_grey"
android:gravity="center"
android:text="PLC连接"
android:textSize="12dp" />
<TextView
android:id="@+id/t_http"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_margin="3dp"
android:layout_weight="1"
android:background="@drawable/round_grey"
android:gravity="center"
android:text="网络连接"
android:textSize="12dp" />
</LinearLayout>
在将后两个TextView设置两行内容的时候,弹出软键盘,TextView位置会向下移。经过一番查阅也没有找到合适的解决方法,只能各种尝试。
最终解决办法:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="57dp"
android:orientation="horizontal"
android:padding="3dp">
<TextView
android:id="@+id/t_blue"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="3dp"
android:layout_weight="1"
android:background="@drawable/round_grey"
android:gravity="center"
android:text="蓝牙连接"
android:textSize="12dp" />
<TextView
android:id="@+id/t_plc"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="3dp"
android:layout_weight="1"
android:background="@drawable/round_grey"
android:gravity="center"
android:text="PLC连接"
android:textSize="12dp" />
<TextView
android:id="@+id/t_http"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="3dp"
android:layout_weight="1"
android:background="@drawable/round_grey"
android:gravity="center"
android:text="网络连接"
android:textSize="12dp" />
</LinearLayout>
将设置TextView高度改为设置LinearLayout的高度,问题就解决了。具体为什么会引起界面错乱,暂时还没有弄明白,如果有大牛路过顺便来讲解一下。