展会信息港展会大全

关于WebVeiw的例子(一) android开发教程
来源:互联网   发布日期:2015-10-02 21:20:33   浏览:1978次  

导读:效果图如上:首先,先把布局文件给大家:先是main.xml?xml version=1.0 encoding=utf-8?LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=vert......

效果图如上:

首先,先把布局文件给大家:

先是main.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

<TextView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/hello"

/>

<EditText

android:hint="www.google.com.hk"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:id="@+id/editText"

/>

<WebView

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:id="@+id/webView"></WebView>

</LinearLayout>

然后是item.xml

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_height="wrap_content" android:paddingBottom="4dip"

android:layout_width="fill_parent">

<ImageView android:layout_height="wrap_content" android:id="@+id/ItemImage"

android:layout_width="wrap_content" android:layout_centerHorizontal="true">

</ImageView>

<TextView android:layout_width="wrap_content"

android:layout_below="@+id/ItemImage" android:layout_height="wrap_content"

android:layout_centerHorizontal="true"

android:id="@+id/ItemText">

</TextView>

</RelativeLayout>

最后是一个很简单但是很重要grid.xml

<?xml version="1.0" encoding="utf-8"?>

<GridView

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_height="wrap_content"

android:layout_width="fill_parent"

android:id="@+id/gridView"

android:gravity="center"

android:numColumns="auto_fit"

android:verticalSpacing="10dp"

android:horizontalSpacing="10dp"

android:columnWidth="90dp"

></GridView>

要记住,不要把GridView写在一个Layout父控件下,不然的话就会报错,因为我们在java代码中是把GridView添加到WebView中,所以Gridview不能有父控件。

赞助本站

人工智能实验室

相关热词: WebVeiw

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港