我正在实施一个应用并制作尺寸竞争力

时间:2016-02-03 11:28:51

标签: android

我正在制作一个Android应用程序并实现一个表,所以我动态地制作所有文本框和编辑框,并动态地给出它们的文本大小 但它不是根据他们的设备大小来。请提前帮助我。 我想根据设备使我的应用尺寸兼容。

tbrow = new TableRow(context);
        tbrow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, 45));
        // tbrow.setPadding(5, 0, 5,0);
        // serial no.
        TextView tv = new TextView(context);

        tv.setGravity(Gravity.CENTER);
        if (buttonchangeCount > 0 && i < saveDataCount) {
            cursor.moveToNext();
            int id = cursor.getInt(cursor.getColumnIndex("loans_id"));
            receiptId.add("" + id);
            tv.setText(id + "");
        } else {
            tv.setText((addButtCount) + "");
        }
        tv.setPadding(10, 10, 5, 10);
        tv.setTextColor(res.getColor(R.color.mainColor));
        if (Login.width >= 1000) {
            tv.setTextSize(25);
            tv.setWidth(121);
        } else if (Login.width >= 480 && Login.width < 1000) {
            tv.setTextSize(15);
            tv.setWidth(242);
            tv.setHeight(96);

        } else if (Login.width >= 320 && Login.width < 480)
            tv.setTextSize(12);
        tv.setBackgroundResource(R.drawable.cell_shape_color);
        sr_no.add(tv);
        tbrow.addView(tv);
        // Bank loan type.
        final Button butt = new Button(context);
        butt.setId(i);

        butt.setGravity(Gravity.CENTER);
        butt.setPadding(5, 10, 5, 10);
        bankLoanType.add(butt);

        if (buttonchangeCount > 0 && i < saveDataCount) {
            String str = cursor.getString(cursor.getColumnIndex("loan_type"));
            butt.setText(str);
            loanstatuslist.clear();
            loanstatuslist.add("New");
            loanstatuslist.add("Renew");
            int id1 = butt.getId();
            if (cursor.getString(cursor.getColumnIndex("loan_type")).equalsIgnoreCase("Term Loan(TL)")) {
                loanstatuslist.remove(1);
                loan_status1.get(id1).setText("New");
            }
            // } else {
            // //loan_status1.get(id1).setText("Select Loan Status");
            // }
            //
        } else {
            // butt.setText("Select Loan Type");
        }
        butt.setTextColor(res.getColor(R.color.mainColor));

        if (Login.width >= 1000) {
            butt.setTextSize(25);
            butt.setWidth(300);
        } else if (Login.width >= 480 && Login.width < 1000)

        {
            butt.setTextSize(14);
            butt.setWidth(604);
            butt.setHeight(92);
        } else if (Login.width >= 320 && Login.width < 480)
            butt.setTextSize(12);
        butt.setBackgroundResource(R.drawable.cell_shape_color);
        butt.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View view) {
                final int id11 = butt.getId();
                AlertDialog.Builder builder = new AlertDialog.Builder(context);
                View layout = BankLoanFragment.this.inflater.inflate(R.layout.list_view,
                        BankLoanFragment.this.container, false);
                ListView listView = (ListView) layout.findViewById(R.id.listView);
                final ArrayList<String> list = new ArrayList<String>();
                list.add("Cash Credit Limit(CCL)");
                list.add("Term Loan(TL)");
                OnlyTextAdapter adapter = new OnlyTextAdapter(context, list);
                listView.setAdapter(adapter);
                adapter.notifyDataSetChanged();
                builder.setView(layout);
                final AlertDialog ad = builder.create();
                listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                        butt.setText(list.get(position).toString());
                        String bt = butt.getText().toString();
                        final int id1 = butt.getId();
                        Log.d("bankLoan", "id1=" + id1);
                        // =
                        // bankLoanType.get(id1).getText().toString().trim();
                        //

                        if (bt.equals("Select Loan Type")
                                && (loanNumber.get(id1).getText().toString().trim().length() <= 0)) {
                            Log.d("bankLoan", "in IF case");
                            cmnBehave.alertMsg("Select Loan type and LoanNumber first.", "Loan Status");
                            // ad.dismiss();
                        } else {
                            loanstatuslist.clear();
                            String str = loan_status1.get(id1).getText().toString();
                            loanstatuslist.add("New");
                            loanstatuslist.add("Renew");
                            if (bt.equals("Term Loan(TL)")) {
                                loanstatuslist.remove(1);
                                loan_status1.get(id1).setText("New");
                                // ad.dismiss();
                            } else
                                loan_status1.get(id1).setText(str);
                        }

                        ad.dismiss();
                    }
                });
                // if(cursor.getInt(cursor.getColumnIndex("bank_loan_status")))
                if (dbutil.getnewStatusIsExists(shgid, meetingDate,
                        (loanNumber.get(id11).getText().toString().trim())) == 0) {
                    // cmnBehave.alertMsg("You have already taken Loan, you
                    // can renew Loan.", "Action");
                    ad.show();
                }

            }
        });

2 个答案:

答案 0 :(得分:0)

您可以使用一个布局文件来使用所有屏幕。

one Layout for all screens

在上面的图片中,使用不同的values(维度)文件夹,布局文件适用于所有屏幕。

values-w320dp ===> For Mobiles

values-w480dp ===> For 7 inch Tablets

values-w820dp ===> For 9 and 10 Tablets

图片中的drawable相同

drawable-normal-hdpi ==>For Mobiles

drawable-large-hdpi ==>For 7 inch Tablets

drawable-xlarge ==>For 9 and 10 Tablets

在布局文件中:

android:layout_marginRight="@dimen/login_edittext"

必须在所有维度文件夹中以相应的值

提及login_edittext

在dimens.xml内的values-w320dp

<dimen name="login_edittext">15dp</dimen>

在dimens.xml内的values-w480dp

<dimen name="login_edittext">30dp</dimen>

在dimens.xml内的values-w820dp

<dimen name="login_edittext">40dp</dimen>

我认为这会对你有帮助..

答案 1 :(得分:0)

如果您要动态创建视图,则应使用显示指标。并动态检查设备的宽度和高度,并根据这些权重为动态视图赋予权重。

使用以下代码获取屏幕宽度和高度。

<强>代码

require 'calabash-cucumber/launcher'
require 'run_loop'

# You can find examples of more complicated launch hooks in these
# two repositories:
#
# https://github.com/calabash/ios-smoke-test-app/blob/master/CalSmokeApp/features/support/01_launch.rb
# https://github.com/calabash/ios-webview-test-app/blob/master/CalWebViewApp/features/support/01_launch.rb

module Calabash::Launcher
  @@launcher = nil

  def self.launcher
    @@launcher ||= Calabash::Cucumber::Launcher.new
  end

  def self.launcher=(launcher)
    @@launcher = launcher
  end
end

Before('@reset_app_btw_scenarios') do
  ENV['RESET_BETWEEN_SCENARIOS'] = '1'
  start_test_server_in_background
end

另外检查以下链接是否对你有用:) link1

link 2