【问题标题】:Create ListView on right side of Activity在Activity右侧创建ListView
【发布时间】:2015-09-23 17:02:55
【问题描述】:

根据下图:
我想要这样的东西

ListView 不是NavigationDrawer,它是Activity 的一部分。
ListView 的项目是数据库的列,当用户选择每个项目时,左侧 (Activity) 应显示该列的其他字段。

我该怎么做?

【问题讨论】:

  • 使用片段的概念
  • 尝试先做。然后,每当您有特定问题时,您可以在这里问stackoverflow.com/help/how-to-askstackoverflow.com/help/dont-ask
  • @Budius 感谢您的提示,但我的问题有什么问题!!?
  • 你没有努力为自己解决问题,只是要求别人为你解决问题。通常,您应该展示您尝试过的内容以及尝试时遇到的具体问题。要求您复制和粘贴代码并不酷。
  • @Budius 你是对的 :)

标签: java android eclipse android-layout listview


【解决方案1】:

这样试试

<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="horizontal">
    <LinearLayout
            android:layout_width="0"
            android:layout_height="match_parent"                       
            android:layout_weight="1">
           //Your UI
    </LinearLayout>
    <LinearLayout
            android:layout_width="0"
            android:layout_height="match_parent"                       
            android:layout_weight="1">
           //Your ListView
    </LinearLayout>

</LinearLayout>

【讨论】:

    【解决方案2】:

    所以您的布局将有一个片段,一个是左片段,一个是右片段

    XML

        <LinearLayout
            orientation:horizontal>
            <FrameLayout
            id=leftFragment
            weight=1/>
            <FrameLayout
            id=rightFragment
            weight=1/>
        </LinearLayout>
    

    Java 代码

    FragmentManager fm=getFragmentManager();
    fm.replace(R.id.leftFragment,new LeftFragment());
    fm.commit();
    

    右片段也是如此

    【讨论】:

    • 您可以在 Right Fragment 中拥有列表视图,在左侧拥有任何布局,使您的左侧布局动态化
    • 当然可以,但问题是我的声誉低于 15,所以我无法投票 :(
    【解决方案3】:

    您应该使用具有水平方向的 LinearLayout,然后有两种布局,一种用于屏幕左侧,一种用于屏幕右侧(使用您的 ListView)。然后你应该为每个布局使用layout_weight 属性,通过声明右边的(ListView)和左边的 0.3 为 0.7,它应该看起来像你的图片

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-08
      • 1970-01-01
      • 2021-05-12
      • 1970-01-01
      相关资源
      最近更新 更多