code:
        mLinerlayout.setPadding(100, 0, 100, 0);
内容会左右缩进100
但是背景色还是填充整个横屏如何改变背景色显示范围?

解决方案 »

  1.   

    在mLinerlayout左右都加上一个宽度为100的layout吧,或者设置绝对布局。
      

  2.   

    在xml中设置以下属性
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:layout_marginLeft="100px"
        android:layout_marginRight="100px"
      

  3.   


    我现在总觉得在xml设置内容ui很死板,喜欢在java里面添加
    然后用LinearLayout.LayoutParams来管理
    xml和LayoutParams好像两者不能并存最近纠结如何使用LayoutParams来把背景做出来圆角效果。
    好像LayoutParams不能添加xml里面的shape
      

  4.   

    比如说我现在写的一个UI:
    自己写了一个类似listview的表格,每行是自己定义的类LinearForList,mList的xml定义:    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center"
        android:id="@+id/listLayout"
        android:background="@layout/listbg"
    java中:mList= (LinearLayout)findViewById(R.id.listLayout);
    line1 = new LinearForList(this,R.drawable.icon1,"播放汽车广告",bStar,"免费", mListWidth, mListHeight); //自己写的类,宽带非全屏,与手机分辨率有关,继承LinearLayout
    mList.addView(line1);
    因为自己写的LinearForList里面是有背景的,
    我现在希望整个的List背景是一个带圆角的背景,
    可是我不知道如何不适用xml来定义圆角,而使用了xml来定义总的list背景,无法和分辨率进行关联
    而且遇到了内容收缩而填充的背景还是全屏的问题
    添加
        android:layout_marginLeft="20px"
        android:layout_marginRight="20px"
    也试过,只要是无法自动收缩正确的像素数所以求教两个点可言解决我的问题:1、xml定义后的内容:mList= (LinearLayout)findViewById(R.id.listLayout);
        如何再去使用LayoutParams来使其可以动态的改变布局2、就是开始提的问题,如何如何改变背景色显示范围?
      

  5.   

    padding是控件里面内容与控件边界的距离,
    可以试设置一下margin(layout_margin),这个是控件与外面控件(或边界)的距离。
      

  6.   

    经过多方查询 发现原来官方api有使用xml来进行java布局的例子
    谢谢上面各位的回答~