作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我用两个按钮创建了 mainLayout
add:添加其他布局
remove : 移除其他布局。
<Button
android:id="@+id/btnAdd"
android:textStyle="bold"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Add View"
android:onClick="addView" />
<Button
android:id="@+id/btnRemove"
android:textStyle="bold"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Remove View"
android:onClick="removeView" />
现在我写了下面的代码来添加 View 当我点击 addView 按钮时
LayoutInflater inflater= (LayoutInflater)this.getSystemService(LAYOUT_INFLATER_SERVICE);
view=inflater.inflate(R.layout.other_layout,null);
mainLayout.addView(view);
View 添加到主布局下方。但我希望 View 在 addView 按钮下方添加(在 removeView 按钮上方而不是在主布局的底部)
我该怎么做?
最佳答案
在两个按钮之间添加一个框架布局。
然后在运行时将您的 View 膨胀到框架布局中。
LayoutInflater inflater= (LayoutInflater)this.getSystemService (LAYOUT_INFLATER_SERVICE); view=inflater.inflate(R.layout.other_layout,null);
myframeLayout.addView(view);
关于android - 如何使用 layout inflatter 在另一个 View 中添加一个 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11407703/
我正在使用 layout-inflatter 来显示自定义警报对话框。但是当 alertdialoge 中的 Textview 包含一个很大的值时,它不会显示.. 当它包含一个小值时,没关系.. 我的
我用两个按钮创建了 mainLayout add:添加其他布局 remove : 移除其他布局。 现在我写了下面的代码来添加 View 当我点击 addView 按钮时
我是一名优秀的程序员,十分优秀!