[英]Change layout_height of Linearlayout
我是Android的初學者。 我有些麻煩 我用名稱,姓氏和電話創建列表,例如地址簿,其中包含一個和切換按鈕,假定它增加了包含所有信息(例如名稱,電話等)的每個單元格的高度...但是什么也沒有發生。 我的代碼如下:
這是我的fragmentlayout.xml
<ListView android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true">
</ListView>
這是我的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>
這是我的主要
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();
}
}
}
所以我想更改rowlayout.xml
的Linear layout,lay的高度和寬度
您為什么要編寫android:layout_height="60dp"
如果您希望基於內容進行擴展),為什么不將其設置為android:layout_height="wrap_content"
但布局卻不一致
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.