0
프로그래밍 방식으로 선형 레이아웃을 만들고 레이아웃 매개 변수로 너비와 높이를 설정하려고합니다. 하지만 레이아웃 매개 변수가 작동하지 않는 것 같습니다.LayoutParams를 설정했지만 안드로이드가 작동하지 않습니다.
// CREATING A NEW LINEAR LAYOUT PROGRAMMATICALLY
LinearLayout linearLayout = new LinearLayout(getActivity());
ViewGroup.LayoutParams layoutParams = new
ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
linearLayout.setLayoutParams(layoutParams);
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
// CREATING CHILDDRENS (TEXT VIEWS)
TextView name = new TextView(getContext(), null, 0, R.style.item_layout_style);
name.setText("Pine");
TextView qty = new TextView(getContext(), null, 0, R.style.item_layout_style);
qty.setText("10");
TextView cost = new TextView(getContext(), null, 0, R.style.item_layout_style);
cost.setText("785");
TextView tCost = new TextView(getContext(), null, 0, R.style.item_layout_style);
tCost.setText("1000");
// SET TEXT VIEW TO LINEAR LAYOUT
linearLayout.addView(name);
linearLayout.addView(qty);
linearLayout.addView(cost);
linearLayout.addView(tCost);
// SET LINEAR LAYOUT TO PINE LAYOUT
LinearLayout daddy= (LinearLayout) view.findViewById(R.id.layout);
daddy.addView(linearLayout, 2);
// Return the view
return view;
나는 많은 선형 레이아웃을 가지고 루트 레이아웃 (아빠) (수직 방향)를 가지고,하지만 난 프로그래밍 방식으로 선형 레이아웃을 생성하고 "아빠"에 것을 추가해야
이
는 코드입니다. 그러나 텍스트 뷰는 서로 붙여져 있으며, 전체 공간을 가로로 가져 오지는 못합니다.도와주세요!
예제를 추가하십시오. – motis10
예를 들어 ???? 적어도 내 코드가 맞는지 말해봐. 그리고 나는 다른 것을보아야한다. –