- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
此 XML 从我的主要 Activity 中膨胀,我想知道如何将膨胀 View 设置为全屏或 fill_parent,如 XML 中所示,因为当我测试我的应用程序时,它会给我一个半尺寸的屏幕显示在右侧。
第一张来 self 的电脑,第二张来 self 的标签。
这是我的 XML 代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal|center_vertical"
android:background="@drawable/splash"
android:paddingBottom="@dimen/_16sdp"
android:paddingLeft="@dimen/_16sdp"
android:paddingRight="@dimen/_16sdp"
android:paddingTop="@dimen/_16sdp" >
<Button
android:id="@+id/g1btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/g1tv2"
android:layout_centerHorizontal="true"
android:text="BUTTON"
android:textSize="@dimen/_70sdp" />
<TextView
android:id="@+id/g1tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text=""THIS""
android:textSize="@dimen/_70sdp" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/g1tv2"
android:layout_centerHorizontal="true"
android:layout_marginBottom="66dp"
android:text="TAP"
android:textSize="@dimen/_70sdp" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="GAME 1"
android:textSize="@dimen/_50sdp" />
</RelativeLayout>
这是我的 MainActivity.Java
public class MainActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
View game1 = getLayoutInflater().inflate(R.layout.game1, null);
RelativeLayout item = (RelativeLayout)findViewById(R.id.Main);
item.addView(game1);
}
最佳答案
问题不在于您的 Wrapping 布局,您正在将一个 View 添加到另一个没有相对于父级的布局参数的 View 。
告诉你的膨胀 View ,这是你 parent 的布局参数,例如:
View view = getLayoutInflater().inflate(R.layout.game1, null);
RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id. Main);
view.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
relativeLayout.addView(view);
这应该可以解决您的问题,而不仅仅是放置一个 LinearLayout 包装它。
祝你好运,编码愉快!
关于android - 如何设置充气 View 全屏或fill_parent?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35497042/
想问一下。有什么区别: LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(Conte
我正在使用 RecyclerView 来保存 CardView 列表。在我运行 Lollipop 5.0.2 的设备上,应用程序运行良好并且列表正确显示数据。然而,在其他 Lollipop 之前的设备
简单:我想用 1 个宽度为 0dp 的子项来膨胀父项。 父级 xml: 子类: public class KeyButton extends RelativeLayout implements Vi
我正在尝试创建一个 android 键盘,现在我希望它只是膨胀,即显示来自 main.xml 的线性布局 这是java文件 package keyboard.rob.com; import ... p
我有以下适配器 public class CardAdapter extends RecyclerView.Adapter{ List list; int id; Context context;
我的 main.xml 中目前有一个 DrawerLayout。 AppBarLayout 中包含了一个 Toolbar,然后是一个简单的 LinearLayout 来交换 fragment 。 我导
由于不推荐使用 Kotlin Synthetics,我们正在迁移到 ViewBinding。 我已经尝试了很多关于 ViewStub、ViewBinding 的谷歌搜索和阅读文档,并为 Fragmen
我无法使用 LayoutInflater 扩充 xml(包含 QuickContactBadge 的布局)文件,以便在 ListView 中使用它。它不会产生编译/运行时错误或正确的预期输出。从 XM
我是一名优秀的程序员,十分优秀!