gpt4 book ai didi

java - Android View 从 .xml 到 .java - 依赖项

转载 作者:行者123 更新时间:2023-12-01 14:38:45 24 4
gpt4 key购买 nike

我只是为了训练而在应用程序上做了一些工作。我很快注意到 .xml 创建的 View 对性能有影响,所以我决定在 Activity 中对它们进行编码。但我不知道如何设置所有这些参数和依赖项,我真的需要创建大量参数吗?这就是我的 .xml 的样子:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="#000000"
tools:context=".MainActivity" >

<ImageButton
android:id="@+id/df_link"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:src="@drawable/df_link"
android:onClick="openWebURL"
android:contentDescription="@string/df_link" />

<TextView
android:id="@+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:textColor="#FFFFFF"
android:text="@string/header"
android:textAppearance="?android:attr/textAppearanceLarge" />

<LinearLayout
android:id="@+id/mm_bottom_row"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:orientation="vertical" >

<Button
android:id="@+id/new_b"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="startNewGame"
android:startColor="#000000"
android:endColor="#000000"
android:textColor="#FFFFFF"
android:text="@string/new_b" />

<Button
android:id="@+id/load_b"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:startColor="#000000"
android:endColor="#000000"
android:enabled="false"
android:text="@string/load_b" />

<Button
android:id="@+id/options_b"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:startColor="#000000"
android:endColor="#000000"
android:enabled="false"
android:text="@string/options_b" />

<Button
android:id="@+id/dev_b"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="loadDevInfo"
android:startColor="#000000"
android:endColor="#000000"
android:textColor="#FFFFFF"
android:text="@string/dev_b" />

<Button
android:id="@+id/wiki_b"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="showWiki"
android:startColor="#000000"
android:endColor="#000000"
android:textColor="#FFFFFF"
android:text="@string/wiki_b" />
</LinearLayout>

</RelativeLayout>

谢谢你帮助我:)

最佳答案

是的,你必须编写很多代码。这就是为什么使用 xml 布局来代替。
This应该有帮助。

关于java - Android View 从 .xml 到 .java - 依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16209678/

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