第40篇 Android Studio实现音乐播放(二)布局及strings.xml

第40篇 Android Studio实现音乐播放(二)布局及strings.xml

3.布局

上篇已说明,布局为整体布局。

3.1.activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/list_background"
    tools:context=".MainActivity">

    <LinearLayout
        android:id="@+id/line_layout"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="horizontal">

        <ImageButton
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:gravity="center"
            android:background="@drawable/back_image"
            android:layout_weight="2"
            android:layout_marginTop="5dp"
            android:layout_marginBottom="5dp"
            android:text="@string/btn_back_name"/>
        <EditText
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginStart="10dp"
            android:layout_marginEnd="10dp"
            android:layout_marginTop="5dp"
            android:layout_marginBottom="5dp"
            android:background="@drawable/edit_background_style"
            android:layout_weight="9"
            android:maxLength="15"
            android:maxLines="1"
            android:autofillHints="11" />

    </LinearLayout>

    <ListView
        android:id="@+id/music_list"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="12"/>

    <LinearLayout
        android:id="@+id/line2_layout"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/music_image"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/background_player1"/>
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:layout_weight="5">
            <com.example.myapplication.MyTextView
                android:id="@+id/music_name"
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:layout_weight="2"
                android:fadingEdge="horizontal"
                android:ellipsize="marquee"
                android:singleLine="true"
                android:focusable="false"
                android:focusableInTouchMode="true"
                android:scrollHorizontally="true"
                android:marqueeRepeatLimit="marquee_forever"
                android:textSize="25sp"
                android:text="@string/music_name"/>
            <TextView
                android:id="@+id/music_player"
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:text="@string/music_player_name"/>
        </LinearLayout>
    </LinearLayout>

</LinearLayout>

这里有一个值得注意:

<com.example.myapplication.MyTextView/>

因为要实现文字滚动的效果,所以得自己重写一下TextView类,具体方法之后再说了。
其他都是常规布局,当然了,记住在三大主体上的占比分配,设置得好就好看些。设置占比就可以实现占满整个屏幕,而且能够把底部和顶部体现出来。

3.2.layout_list_view

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <TextView
        android:id="@+id/txt_music_name"
        android:layout_width="match_parent"
        android:layout_weight="4"
        android:layout_height="wrap_content"
        android:textSize="20sp"
        android:text="@string/music_name"/>
    <TextView
        android:id="@+id/txt_music_player"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/music_player_name"/>

</LinearLayout>

这是给listview专门写的一个布局文件,就是listview每一行要显示的内容有哪些,需要怎样布局,在这里设置好之后,再通过适配器设置,就能够显示对应的信息了。(比如csdn的是一个标题,三张图片,标题在上,图片在下)。

4.strings.xml

<resources>
    <string name="app_name">音乐</string>
    <string name="btn_back_name">返回</string>
    <string name="music_name">音乐名称</string>
    <string name="music_player_name">歌手</string>
</resources>

既然有这个文件,那它肯定是有必要的,而且在这里设置之后,使用起来也挺方便(主要是有强迫症,不想看到那么多的警告,看到就想解决掉)。

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大唐不良猿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值