【问题标题】:Xml background for android appandroid应用程序的xml背景
【发布时间】:2013-02-23 23:42:45
【问题描述】:

我想为我的 android 应用程序制作一个背景 xml,我附上了相同的图像,但我不知道如何制作,请帮助我。谢谢!

【问题讨论】:

    标签: android background


    【解决方案1】:

    试试这个例子实验并自己探索,你可能会学到:)

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
       <gradient
          android:startColor="#FFFFFF"
          android:endColor="#808080"
          android:angle="270" />
    </shape>
    

    也试试这个。

    <shape>
       <solid
          android:color="#449def" />
       <stroke
          android:width="2dp"
          android:color="#2f6699" />
       <corners
          android:radius="3dp" />
       <padding
          android:left="15dp"
          android:top="15dp"
          android:right="15dp"
          android:bottom="15dp" />
    </shape>
    

    别忘了把它们放在你的drawable文件夹中。

    【讨论】:

      【解决方案2】:

      这种方式解决了我的需求,但任何人都有更好的方式

      <?xml version="1.0" encoding="utf-8"?>
      <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
      <item>
          <shape android:shape="rectangle"> 
              <solid android:color="#017db1"/>
           </shape>
      </item>
      
      <item android:top="1px">
          <shape android:shape="rectangle" >
             <solid android:color="#ffffff"/>
          </shape>
      </item>
      
      
      <item android:top="2px">
          <shape android:shape="rectangle"> 
              <solid android:color="#017db1"/>
           </shape>
      </item>
      

      【讨论】:

        【解决方案3】:

        我假设您是 Android 新手开发人员。

        不要说应用程序。当您使用基于活动的 Android 开发时。

        我假设您有一个名为 MyActivity.java 的主 Activity。在 onCreate 方法中,您必须添加一行代码,告诉 Activity 使用自定义布局,例如:

        setContentView(R.layout.my_layout);
        

        然后你必须在文件夹/res/layout 中创建一个名为my_layout.xml 的布局xml,其中至少包含一个布局组件:

        <?xml version="1.0" encoding="utf-8"?>
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/my_bg_image"
            android:orientation="vertical" >
        </LinearLayout>
        

        注意使用自定义图像的背景属性。此图像必须以 my_bg_image.jpg 的形式保存在项目的 /res/drawable 文件夹中。

        这是一个开始。不断改进。

        【讨论】:

        • 问题是关于make a background xml for my android app不要像你在这里所说的那样使用图像This image must be saved in the /res/drawable folder in your project as my_bg_image.jpg.
        • 谢谢亚历山德罗亚历山德拉,但我不想使用图像。我需要一个xml背景文件
        • 对不起,我误解了这个问题。我应该删除它吗?
        猜你喜欢
        • 2012-07-14
        • 1970-01-01
        • 2017-02-06
        • 2016-06-09
        • 1970-01-01
        • 2012-12-25
        • 1970-01-01
        • 2016-09-06
        • 1970-01-01
        相关资源
        最近更新 更多