简体   繁体   中英

Change layout_height of Linearlayout

I am a beginner at Android. I have some troubles. I create list with names,surnames and phones something like address book, which contain and a toggle button, which suppose its increase the height of each cell which contains all the info like name,phone etc... But nothing happen. My code is below:

This is my fragmentlayout.xml

<ListView android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true">

</ListView>

This is my rowlayout.xml

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/lay"
    android:layout_width="wrap_content"
    android:layout_height="60dp"
    android:orientation="vertical" >
    <TextView
        android:id="@+id/txtitem"
        android:layout_width="wrap_content"
        android:layout_height="60dp"
        android:padding="10dp"
        android:textSize="10sp"
        />

</LinearLayout>

And this is my main

 package com.example.serepasf.my_app2;

    import android.app.Activity;
    import android.app.ListActivity;
    import android.content.Context;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.util.Log;
    import android.widget.CompoundButton;
    import android.widget.LinearLayout;


    import android.support.v4.app.FragmentActivity;
    import android.support.v4.app.FragmentTransaction;
    import android.widget.ToggleButton;

    public class MainActivity extends FragmentActivity {

        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.fragmentlayout);
           ToggleButton toggle = (ToggleButton) findViewById(R.id.toggleButton);
           toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (isChecked) {
                        LinearLayout l = (LinearLayout) findViewById(R.id.lay);
                        l.setLayoutParams(new LinearLayout.LayoutParams(320,320));
                        // The toggle is enabled
                    } else {
                        // The toggle is disabled
                    }
                }
            });
            LstFragment lstfragment=(LstFragment)getSupportFragmentManager().findFragmentByTag("lstfragment");
            if(lstfragment==null){
                lstfragment=new LstFragment();
                FragmentTransaction transact=getSupportFragmentManager().beginTransaction();
                transact.add(android.R.id.content,lstfragment,"lstfragment");
                transact.commit();

            }
        }

    }

So I want to change the height and width of Linear layout,lay which is in rowlayout.xml Thanks

您为什么要编写android:layout_height="60dp"如果您希望基于内容进行扩展),为什么不将其设置为android:layout_height="wrap_content"但布局却不一致

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM