使用php文件向android应用程序添加广告

使用php文件向android应用程序添加广告,php,android,ads,Php,Android,Ads,我已经创建了android应用程序,可以像whatsapp一样聊天。但我想在广告的指定位置和内容显示广告,如标题、链接、,将使用php文件获取图像。因此,我如何才能做到这一点。如果您知道,请帮助我。我搜索了很多,但没有找到解决方案。我通过创建弹出窗口解决了这个问题…我创建了包含TextView、ImgaView、Button等的小型条形布局。 popup.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xml

我已经创建了android应用程序,可以像whatsapp一样聊天。但我想在广告的指定位置和内容显示广告,如标题、链接、,将使用php文件获取图像。因此,我如何才能做到这一点。如果您知道,请帮助我。我搜索了很多,但没有找到解决方案。

我通过创建弹出窗口解决了这个问题…我创建了包含TextView、ImgaView、Button等的小型条形布局。 popup.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="@+id/popup"
android:color="#66FF0000" 

android:layout_height="wrap_content"
android:background="#fff"
>

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:src="@drawable/ic_launcher" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView1"
    android:layout_below="@+id/textView1"
    android:textColor="#fff"
    android:text="Ad Description" />

<Button
    android:id="@+id/button1"
    style="?android:attr/buttonStyleSmall"
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:background="@drawable/close"
     />

<TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView2"
    android:layout_toRightOf="@+id/textView1"
    android:textColor="#fff"
    android:text="www.nspiresfot.com" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:textColor="#fff"
    android:layout_toRightOf="@+id/imageView1"
    android:text="Ad Title" />

<Button
    android:id="@+id/btn_openAd"
    style="?android:attr/buttonStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/textView2"
    android:layout_alignBottom="@+id/textView2"
    android:layout_toLeftOf="@+id/button1"
    android:background="@drawable/send" />

然后,我使用php文件加载所有textview和imageview。

我正在使用,但如果您想使用自己的网页广告,请使用webview加载您的网页。我已经了解了admob,但我想将自己的广告发布到我的应用程序中添加一个webview加载您的网页php网页,然后按下按钮时,您可以打开网页上的链接其他应用程序取决于链接。但我不想使用webview。我只想将Linearlayout与TextView、ImageView一起使用,并在后台从php文件加载TextView和ImageView。对不起,您能发布您的php文件到底显示了什么吗?是休息服务吗?
package com.popwindow;

import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.content.Context;
import android.graphics.Point;
import android.graphics.drawable.BitmapDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

public class MainActivity extends Activity {
Point p;
 PopupWindow popup;
@Override
public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_main);

   Button btn_show = (Button) findViewById(R.id.show_popup);
   p = new Point();
   p.x = 0;
   p.y =60;
   //Open popup window
 new Handler().postDelayed(new Runnable() {

    public void run() {
        if (p != null)
          showPopup(MainActivity.this, p);
    }
}, 900L);
}


// The method that displays the popup.
private void showPopup(final Activity context, Point p) {
   int popupWidth = 240;
   int popupHeight = 50;

   //Inflate the popup_layout.xml
   LinearLayout viewGroup = (LinearLayout) context.findViewById(R.id.popup);
   LayoutInflater layoutInflater = (LayoutInflater) context
     .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
   View layout = layoutInflater.inflate(R.layout.popup_layout, viewGroup);
   layout.getBackground().setAlpha(90);
   //Creating the PopupWindow
   popup = new PopupWindow(context);
   popup.setContentView(layout);
   popup.setWidth(popupWidth);
   popup.setHeight(popupHeight);

   popup.setFocusable(false);

   // Some offset to align the popup a bit to the right, and a bit down, relative to button's position.
   int OFFSET_X = 0;
   int OFFSET_Y = 0;

   // Clear the default translucent background
   popup.setBackgroundDrawable(new BitmapDrawable());

   // Displaying the popup at the specified location, + offsets.
   popup.showAtLocation(layout, Gravity.NO_GRAVITY, p.x + OFFSET_X, p.y + OFFSET_Y);
  // popup.showAtLocation(layout,  Gravity.NO_GRAVITY, getRequestedOrientation(), getRequestedOrientation());
   // Getting a reference to Close button, and close the popup when clicked.
   Button close = (Button) layout.findViewById(R.id.button1);
   close.setOnClickListener(new View.OnClickListener() {

     @Override
     public void onClick(View v) {
       popup.dismiss();
     }
   });
}

@Override
protected void onDestroy() {
    // TODO Auto-generated method stub
    super.onDestroy();
     popup.dismiss();
}

}