qq_26771417 2016-08-17 10:01 采纳率: 0%
浏览 2678
已结题

安卓setVisibility和setTop设置控件位置无效冲突!

showtext = showlist.getText().toString().trim();
if (showtext.equals("显示列表")) {
//设置包裹lv的linearlayout为VISIBLE
ll_lv.setVisibility(View.VISIBLE);
//endheight是2/3的屏幕高度
int endheight = mHeight * 2 / 3;
//设置top为2/3的屏幕高度的位置
ll_lv.setTop(endheight);
int top = lv.getTop();
int buttom = lv.getBottom();
//改变textview文字
showlist.setText("隐藏列表");
} else {
//设置包裹lv的linearlayout为GONE
ll_lv.setVisibility(View.GONE);
//设置top为屏幕高度的位置
ll_lv.setTop(mHeight);
showlist.setText("显示列表");
}

布局文件:
<?xml version="1.0" encoding="utf-8"?>
android:id="@+id/rl"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!--
<!--android:id="@+id/title"-->
<!--android:background="@color/blue"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:text=""-->
<!--android:gravity="center"-->
<!--android:textSize="@dimen/font_32"-->
<!--android:padding="15dp"/>-->
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">

    <com.amap.api.maps2d.MapView
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <LinearLayout
        android:id="@+id/ll_lv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|right"
        android:background="#fff"
        android:orientation="vertical"
        android:padding="5dp">

android:id="@+id/tv_tuch"
android:layout_width="match_parent"
android:background="@color/black"
android:layout_height="wrap_content"/>
android:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">

</FrameLayout>
<LinearLayout
    android:id="@+id/ll_show"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">


<View
    android:id="@+id/view"
    android:layout_width="match_parent"
    android:layout_height="0.5dp"
    android:background="#d0d0d0"/>

<TextView
    android:id="@+id/showlist"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:padding="15dp"
    android:text="显示列表"/>
</LinearLayout>



想要实现效果:
图片说明
点击隐藏列表 列表隐藏 点击显示列表 列表显示出来;
但是现在是 用VISIBLE,gone的话listview就全部显示出来了,不用gone的话一开始列表就显示出来了 不符合我们业务需求

    求大神指点一二。
  • 写回答

2条回答 默认 最新

  • devmiao 2016-08-17 15:17
    关注
    评论

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)