layout_marginLeft,layout_marginRight设置不可以吗?

解决方案 »

  1.   

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <View
            android:layout_weight="1.0"
            android:background="@null"
            android:layout_width="0dp"
            android:layout_height="1dp"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="Left Button"
            />
        <View
            android:layout_weight="1.0"
            android:background="@null"
            android:layout_width="0dp"
            android:layout_height="1dp"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="Right Button"
            />
        <View
            android:layout_weight="1.0"
            android:background="@null"
            android:layout_width="0dp"
            android:layout_height="1dp"/>
    </LinearLayout>
      

  2.   

    s的left和c的right设置margin为 m
    s的right和c的left设置margin m/2
      

  3.   


    请问bdmh:   这个m 怎么确定是多少呢?   也就是 多少 dp呢比如说 设置的<dimen name="btn_width">30mm</dimen>  也就是 设置的 button的宽是 30mm,那么就应该 假设 屏幕的总宽为 L,   那么 m=  ( L  -  2*30 )/3但是  关键是  L 怎么知道是多少呢?
    -----------------------------------------------
    另外 我在  res/layout/test_dimen.xml 里边:
    <LinearLayout
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1">
            
        <Button 
            android:text="@string/test_scan"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="5dp"
            android:id="@+id/Button01"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"></Button>
        
        <Button 
            android:text="@string/test_control"
            android:layout_marginRight="5dp"
            android:layout_marginLeft="10dp"
            android:id="@+id/Button02"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"></Button>
        
        </LinearLayout>然后 在 在启动的 activity 文件里边:
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.test_dimen);但是 运行的效果  并不是想要的结果。  能说下  问题出在哪里吗?  具体怎么写呢?
      

  4.   


    请问bdmh:   这个m 怎么确定是多少呢?   也就是 多少 dp呢比如说 设置的<dimen name="btn_width">30mm</dimen>  也就是 设置的 button的宽是 30mm,那么就应该 假设 屏幕的总宽为 L,   那么 m=  ( L  -  2*30 )/3但是  关键是  L 怎么知道是多少呢?
    -----------------------------------------------
    另外 我在  res/layout/test_dimen.xml 里边:
    <LinearLayout
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1">
            
        <Button 
            android:text="@string/test_scan"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="5dp"
            android:id="@+id/Button01"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"></Button>
        
        <Button 
            android:text="@string/test_control"
            android:layout_marginRight="5dp"
            android:layout_marginLeft="10dp"
            android:id="@+id/Button02"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"></Button>
        
        </LinearLayout>然后 在 在启动的 activity 文件里边:
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.test_dimen);但是 运行的效果  并不是想要的结果。  能说下  问题出在哪里吗?  具体怎么写呢?

    如果你的BUTTON宽度固定的话完全可以看看2L的方法,如果不需要的话,像上面的代码,Button的Width设为0dip,增加Weigth=1属性自适应宽度。
      

  5.   

    左右button的weight=1,然后marin 为l,l/2;