gpt4 book ai didi

android - 如何设置充气 View 全屏或fill_parent?

转载 作者:可可西里 更新时间:2023-11-01 11:42:55 24 4
gpt4 key购买 nike

此 XML 从我的主要 Activity 中膨胀,我想知道如何将膨胀 View 设置为全屏或 fill_parent,如 XML 中所示,因为当我测试我的应用程序时,它会给我一个半尺寸的屏幕显示在右侧。

enter image description here

第一张来 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="&quot;THIS&quot;"
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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com