3

有人帮我做下面的事情!我想在 main.xml 文件的底部插入一些列表 list.xml 文件。如何实施?

   ----------------------------
    |    main.java              |
    |    main.xml               |
    |                           |
    |                           |
    |                           |
    |                           |
    |      ______               |
    |     |button|              |
    |                           |
    |                           |
    |                           |
    | _________________________ | 
    | |      list.java        | |
    | |      list.xml         | |
    | |                       | |
    | |                       | |
    | |                       | |
    | |                       | |
    | |                       | |
    |_|_______________________|_| 

I called list.java by using intent on the main.java .I also include list.xml to main.xml. When I press button list.xml should pop up like above figure. But list.xml comes up new window. How to solve this problem?
4

3 回答 3

2

Yoy可以这样尝试...

我的示例代码...

<RelativeLayout
    android:id="@+id/xK1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:orientation="vertical"
    >

    <include
        android:id="@+id/your id"// your id
        layout="@layout/list" >// add the list.xml here
    </include>
</RelativeLayout>

添加到您的 Main.xml 中。

于 2012-11-20T06:37:11.227 回答
2

尝试以下代码并根据您的要求进行一些更改。这只是指导代码。为此使用布局充气机服务。假设您有 2 个主要文件,然后列出

public class Test extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    LinearLayout layoutMain = new LinearLayout(this);
    layoutMain.setOrientation(LinearLayout.HORIZONTAL);
    setContentView(layoutMain);
    LayoutInflater inflate = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    RelativeLayout layoutLeft = (RelativeLayout) inflate.inflate(R.layout.main, null);
    RelativeLayout layoutRight = (RelativeLayout) inflate.inflate(R.layout.list, null);

    RelativeLayout.LayoutParams relParam = new RelativeLayout.LayoutParams(
    RelativeLayout.LayoutParams.WRAP_CONTENT,
    RelativeLayout.LayoutParams.WRAP_CONTENT);
    layoutMain.addView(layoutLeft, 100, 100);
    layoutMain.addView(layoutRight, relParam);
}
}
于 2012-11-20T06:38:27.340 回答
1

由于您想重用布局,即将现有布局包含在另一个布局中,我建议您阅读这篇文章:Re-using Layouts with<include/> .

现在,当您想在 main.xml 中包含 list.xml 时,请在 main.xml 中编写<include/>如下:

 <include layout="@layout/list"/>
于 2012-11-20T06:43:17.013 回答