# 原生广告

<div align="left"><figure><img src="https://3612726722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F79UQRI7S2eHbTf7duI78%2Fuploads%2Fo9mDtu4fsrbinvEs1rsL%2F%E5%8E%9F%E7%94%9F%E5%B9%BF%E5%91%8A.png?alt=media&#x26;token=5328f0d2-665b-4db6-ac4d-fe96e63484a5" alt=""><figcaption></figcaption></figure></div>

原生广告是通过用户根据自身业务布局与功能进行构建布局后，配合原生广告规则进行广告内容填充和展示，做到广告与应用风格和元素适配，达到浑然一体的效果

当前指南功能展示原生广告控件使用方法以及相关配套模版使用规则与使用

## 前提

用户完成广告初始化步骤[ru-men-zhi-nan](https://docs.adx3.io/copy-of-cn/jie-kou-wen-dang/android/kai-shi/ru-men-zhi-nan "mention")

## 布局中添加View

用户布局中，添加原生广告view与内部展示控件,当前组件采用基础TextView，ImageView与Video控件

```java
<io.adx3.library.view.Adx3UserView
        android:id="@+id/view_user"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="parent"
        app:unitId="UnitId">

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:scaleType="fitXY"
            android:src="@mipmap/ic_launcher"
            app:layout_constraintLeft_toLeftOf="parent" />

        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView"
            android:textColor="@color/black"
            app:layout_constraintLeft_toRightOf="@+id/imageView" />

        <io.adx3.library.view.videoplayer.player.Adx3VideoView
            android:id="@+id/video_user"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_marginTop="10dp"
            app:layout_constraintTop_toBottomOf="@+id/imageView" />

    </io.adx3.library.view.Adx3UserView>
```

* **app:unitId - 当前广告位id，当前为原生广告位配置，用户可在xml页面填充或在界面控件初始化后设置，参考如下**

{% hint style="danger" %}
若未在XML或代码中完成广告位配置填充，会导致广告加载失败，影响广告展示效果
{% endhint %}

## 完整控件使用示例

```java
public class UserAInsertctivity extends AppCompatActivity {

    TextView textView;
    ImageView imageView;
    Adx3UserView view_user;
    Adx3VideoView video_user;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.xml);
        initView();
        setUserView();
    }


    private void initView() {
        textView = findViewById(R.id.textView);
        imageView = findViewById(R.id.imageView);
        view_user = findViewById(R.id.view_user);
        video_user = findViewById(R.id.video_user);
    }

    private void setUserView() {
        //if you don't set the UnitId in XML 
        //view_user.setUnitId("UnitId");
        view_user.setImageView(imageView);
        view_user.setVideoView(video_user);
        view_user.setTextView(textView);
        view_user.load();
    }

}
```

{% hint style="success" %}
好了，到此，原生广告添加完成，执行load广告加载方法后，会自动填充广告到控件中，实现控件适配应用主题与风格
{% endhint %}

## 备注

当前原生广告默认仅支持文本，图片，视频三种元素
