java - Eclipse, ImageView 上的 View 布局

标签 java android eclipse view android-inflate

所以我有一门叫做书的类(class)。本书既是一个java类,也是一个用于布局的xml文件。然后我有一个名为 book_shelf 的 class/xml 文件。在我的 book_shelf xml 文件中,我有一个名为 book1 的 View 。

public class book_shelf extends Activity {
@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.mainmenu, menu);

        book MyBook = new book();
        final View book1 = (View) findViewById(R.id.book1);
        book1.(load my book xml layout in this view)
        return true;

    }

}

我想将书籍布局加载到书架框架的 View 中。请并谢谢您。

最佳答案

您需要使用充气器来充气所需的布局,然后将布局添加到 View 中。 例如

book MyBook = new book();
final View book1 = (View) findViewById(R.id.book1);

LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

//assuming R.layout.book your book xml
View bookView = inflater.inflate(R.layout.book, null);

//Add bookView layout to your book1.
book1.addView(bookView)

编辑: 试试这个

final View book1 = (View) findViewById(R.id.book1);
((ViewGroup) book1).addView(bookView, 0, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));

关于java - Eclipse, ImageView 上的 View 布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20778848/

相关文章:

java - 无法实例化类 - p :filedownload called before f:setPropertyActionListener

java - 空文件上传到ftp服务器

Java - 在构造函数中初始化 arraylist

java - Android Studio 中的 Osmand

android - ADT更新后的java.lang.NoClassDefFoundError : com. google.android.gms.gcm.GoogleCloudMessaging

eclipse - 无法在 Eclipse 中安装 SVN 连接器

java - 填写pdf表格后数字签名失效

android - Crosswalk 与 cordova 集成

android - Gridview getChildAt 隐藏字段

Eclipse 导入项目错误,工作区位置重叠