【问题标题】:Master-detail layout on AndroidAndroid 上的主从布局
【发布时间】:2012-04-03 09:32:22
【问题描述】:

我有一个应用程序,其中一个选项卡有一个任务列表。我的意图是,当我单击该列表的一个元素时,我想查看该任务的详细信息。是否可以在同一页面中查看该任务的列表和详细信息?我正在使用 Eclipse。

【问题讨论】:

标签: android layout master-detail


【解决方案1】:

您可以自己编写代码,方法是使用视图及其可见性/大小。 或者你可以使用片段:http://developer.android.com/guide/topics/fundamentals/fragments.html

【讨论】:

    【解决方案2】:

    你可以在列表视图项目上打开PopupWindow,单击并显示所选项目的详细信息。要在项目上打开 PopupWindow,请单击 see

    【讨论】:

      【解决方案3】:

      如果出于某种原因您不想使用片段(例如,您永远不会重复使用此视图),您也可以这样做 - 简单易行:

      这将是您的分屏布局 splitscreen.xml

      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/linearLayout1"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:orientation="horizontal" >
      
          <LinearLayout
              android:id="@+id/task_list_wrap"
              android:layout_width="wrap_content"
              android:layout_height="fill_parent"
              android:orientation="vertical"
              android:padding="2dp" >
      
              <ListView
                  android:id="@+id/task_list"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:overScrollMode="never" >
              </ListView>
          </LinearLayout>
      
          <LinearLayout
              android:id="@+id/task_details"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:orientation="vertical">
      
              <TextView
                  android:id="@+id/task_details_description"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:text="this is description text" />
          </LinearLayout>
      
      </LinearLayout>
      

      当您在活动中单击这样的任务列表时,您将更改任务详细信息面板的内容:

      setContentView(R.layout.splitscreen);
      ListView taskList= (ListView) findViewById(R.id.task_list);
      TextView taskDescription = (TextView) findViewById(R.id.task_details_description);
      taskList.setOnItemClickListener(new OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view,
              int position, long id) {
              int selectedTask = position;
              updateTaskDescription(selectedTask, taskDescription);
          }
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多