要实现下面的布局(先思考下如何实现,看似简单,或许会有所收获)
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.example.weixinrecorder.view.AudioRecorderButton
android:id="@+id/id_recorder_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginTop="6dp"
android:layout_marginBottom="7dp"
android:background="@drawable/btn_recorder_normal"
android:gravity="center"
android:padding="5dp"
android:text="@string/str_recorder_normal"
android:textColor="#727272"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#ccc"/>
</FrameLayout>
我们会发现一个问题,就是Button的高度有些高,那是因为其本身所包含的默认高度所致,可以添加android:minHeight="0dp"
属性再试试,修改如下:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.example.weixinrecorder.view.AudioRecorderButton
android:id="@+id/id_recorder_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="0dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginTop="6dp"
android:layout_marginBottom="7dp"
android:background="@drawable/btn_recorder_normal"
android:gravity="center"
android:padding="5dp"
android:text="@string/str_recorder_normal"
android:textColor="#727272"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#ccc"/>
</FrameLayout>
再看看效果:
应该学到两点:1. FrameLayout所起到的作用 2. Button的显示高度
下面是整个项目的下载地址:
https://download.csdn.net/download/hanmindi/10276242