Android 如何接入今日头条屏幕适配方案,如何使用请见下文

文章介绍了如何在Android项目中进行今日头条屏幕适配,包括添加依赖包,配置AndroidManifest.xml中的设计尺寸,以及当Gradle无法下载资源时,如何改用阿里云镜像来解决问题。提供了具体的代码示例和适配后的布局文件内容。
摘要由CSDN通过智能技术生成

1.下载今日头条屏幕适配的依赖包

implementation 'me.jessyan:autosize:1.2.1'

2.在AndroidManifest.xml中配置参数,根据设计图的尺寸填写宽度和高度,一般写宽度就可以了。一般设计师是以375宽度进行设计

<manifest>
    <application>    
        ...
        <meta-data
            android:name="design_width_in_dp"
            android:value="360"/>
        <meta-data
            android:name="design_height_in_dp"
            android:value="640"/>      
        ...
     </application>           
</manifest>

3.如果下载不下来,出现报错内容如下

Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':app:debugRuntimeClasspath'.

Caused by: org.gradle.internal.resolve.ModuleVersionNotFoundException: Could not find me.jessyan:autosize:1.2.1.

那么可以这样修改。
如果构建项目时拉取不到gradle资源,可以将地址修改成阿里云的国内镜像。解决方式如下:

问题解决
打开build.gradle文件,加入代码        
 maven{ url 'https://maven.aliyun.com/repository/google'}
        maven{ url 'https://maven.aliyun.com/repository/jcenter'}如下所示:

 repositories {
         //加入代码
        maven{ url 'https://maven.aliyun.com/repository/google'}
        maven{ url 'https://maven.aliyun.com/repository/jcenter'}
    }
allprojects {
    repositories {
        //加入代码
        maven{ url 'https://maven.aliyun.com/repository/google'}
        maven{ url 'https://maven.aliyun.com/repository/jcenter'}
    }
}

最后屏幕适配的效果如下图,这是360dp的宽度
在这里插入图片描述
这是适配的布局文件内容。如下代码

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.xf.ap.MainActivity2">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/textView3"
            android:layout_width="180dp"
            android:layout_height="50dp"
            android:background="@color/teal_200"
            android:text="TextView" />

        <TextView
            android:id="@+id/textView4"
            android:layout_width="180dp"
            android:layout_height="50dp"
            android:background="@color/purple_500"
            android:text="TextView" />
    </LinearLayout>

</RelativeLayout>
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值