0
テーブルのアイテムのリストを動的に表示しています。テーブル内の各アイテムが親オブジェクトの中に均等に広がっていることを確認するために、重みが.33f(各行に3つのアイテムがあります)の各アイテムに対して.setLayoutParams()
を呼び出しています。しかし、項目は行間で均等に分散し続けることはありません。LinearLayout.LayoutParamsでアイテムの重量が正しく設定されない
私PaymentConfirmedActivity.java
パッケージcom.snapwebdevelopment.scanhappyためのコードと、
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.widget.LinearLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import com.google.android.gms.vision.text.Text;
import com.snapwebdevelopment.scanhappy.firebasemodels.Product;
import com.snapwebdevelopment.scanhappy.managers.ShoppingListManager;
import java.util.List;
public class PaymentConfirmedActivity extends AppCompatActivity {
private TableLayout purchasedItems;
private List<Product> purchases;
private ShoppingListManager mShoppingListManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_payment_confirmed);
mShoppingListManager = ShoppingListManager.getInstance();
purchases = mShoppingListManager.getProductList();
Product p;
purchasedItems = (TableLayout) findViewById(R.id.purchasedItems);
for(Integer i = 0; i < purchases.size(); i++) {
TextView purchaseName;
TextView purchaseQuantity;
TextView purchasePrice;
p = purchases.get(i);
TableRow row = new TableRow(this);
TableRow.LayoutParams layoutParams = new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT);
LinearLayout.LayoutParams tvParams = new LinearLayout.LayoutParams(
MATCH_PARENT,
MATCH_PARENT,
0.33f);
row.setLayoutParams(layoutParams);
purchaseName = new TextView(this);
purchaseName.setText(p.getName());
purchaseName.setTextColor(Color.WHITE);
purchaseName.setLayoutParams(tvParams);
row.addView(purchaseName);
purchaseQuantity = new TextView(this);
purchaseQuantity.setText(String.valueOf(p.getQuantity()));
purchaseQuantity.setTextColor(Color.WHITE);
purchaseQuantity.setLayoutParams(tvParams);
row.addView(purchaseQuantity);
purchasePrice = new TextView(this);
purchasePrice.setText("$" + String.valueOf(p.getPrice()));
purchasePrice.setTextColor(Color.WHITE);
purchasePrice.setLayoutParams(tvParams);
row.addView(purchasePrice);
purchasedItems.addView(row, i);
}
}
}
私の活動のレイアウト
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_shopping_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:background="@color/colorPrimary"
tools:context="com.snapwebdevelopment.scanhappy.PaymentConfirmedActivity">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
layout="@layout/toolbar_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TableLayout
android:id="@+id/purchasedItems"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="20dp"
android:paddingTop="5dp"
android:paddingRight="20dp"
android:layout_weight="1" />
</LinearLayout>
<Button
android:id="@+id/checkoutButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:textColor="@color/colorButtonTextPrimary"
android:background="@color/colorPrimary"
android:text="Total Payed $12.12"
android:shadowColor="@color/colorButtonShadow"/>
</RelativeLayout>
どのように私は、各行の私の3 TextViewsが均等に均等に広がっていることを確認していますか?
無関係、まだ:あなたは代わりに「払っ」の「有給」と言うする必要があります:) – Aenadon