关于WebVeiw的例子(一)

效果图如上:

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

先是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不能有父控件。

java代码如下:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值