在Android中会有遇到这种情况,在动态添加列表型数据时,在不用listview,RecyclerView等情况下用列表形式展示数据,那么久用到绝对布局中LinerLayout进行动态设置。先了解一下LinerLayout有哪些属性,我们用到哪几种。我们就了解常用的吧

  • android:orientation=”vertical”//设置重心,horizontal横向显示,在我们用到的就是vertical,纵向显示的
 <LinearLayout        android:id="@+id/linerAdd"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:orientation="vertical" />

先看看Activity中的代码

public class LinearActivity extends Activity {    private LinearLayout linerAdd;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_linear);        linerAdd = (LinearLayout) findViewById(R.id.linerAdd);        init();    }    public void init() {        //先添加5条数据        linerAdd.removeAllViews();//移除        for (int i = 0; i < 5; i++) {            View view = LayoutInflater.from(this).inflate(R.layout.item_linear, null);            TextView tv_content = (TextView) view.findViewById(R.id.tv_content);            tv_content.setText("我是第" + i + "条");            linerAdd.addView(view);        }    }}

我们先看看效果

这个没有线条,那么我们加一条 横线

现在有了,这个是怎么做到的呢,很简单,在子布局中增加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="match_parent"    android:orientation="vertical">    <View        android:layout_width="match_parent"        android:layout_height="0.2dp"        android:background="#e9e9e9" />    <TextView        android:id="@+id/tv_content"        android:layout_width="match_parent"        android:layout_height="50dp"        android:gravity="center_vertical"        android:paddingLeft="10dp"        android:singleLine="true"        android:text="Large Text"        android:textColor="#000"        android:textSize="16sp" />    <View        android:layout_width="match_parent"        android:layout_height="0.2dp"        android:background="#e9e9e9" />LinearLayout>

说了这么多怎么跟标题符合呢,嘿嘿,我们再看一下另一个效果

很明显,箭头部分的横线要粗一些,因为这是主布局中的View和子布局中View重合了,那么解决这个就是去掉主布局中View就行了

更多相关文章

  1. Android开发--Intent-filter属性详解
  2. MediaStore与Media.EXTERNAL_CONTENT_URI
  3. Adapter相关资料
  4. FFmpeg In Android(安卓)- 多媒体文件解封装/解码/保存Yuv
  5. 简析Android五大布局(LinearLayout、FrameLayout、RelativeLayout
  6. 【Android开发进阶】Android屏幕适配全攻略(最权威的官方适配指
  7. Android中的Http请求
  8. Android(安卓)数据存取试验 (二)
  9. Android(安卓)UI之布局

随机推荐

  1. Android(安卓)L 64位兼容32 应用程序的认
  2. android:通过Android命令自动编译出build.
  3. android获取网络图片的用法 BitmapFactor
  4. Android之Path类
  5. Android StaggeredGridLayoutManager布局
  6. android studio加载so文件报错:dalvik.sys
  7. android 入门之四【应用工程文件组成详解
  8. 手机上运行Python
  9. sp 强指针类的用法
  10. android studio 小技巧之 图片预览