EditText,输入的文本不完整 [英] EditText ,Entered text not visible full

查看:83
本文介绍了EditText,输入的文本不完整的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要以编程方式在网格布局"中具有编辑文本"的示例代码.但是当在应用程序中输入文本时,仅文本的一小部分可见.该文本比预期的大.我需要带有文本的编辑文本,如图像中所示,该文本是绿色的编辑文本"背景,只需要一行编辑文本.谢谢

A sample code where i need to have a Edit Text in a Grid Layout Programatically .But when the text are entered in the app ,Only the small bottom portion of text is visible .The text is larger than expected. I need the edit text with text as shown in image which is Edit Text green background with only one line edit text required.Thanks

package com.example.myapplicationtesting;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.GridLayout;

public class MainActivity extends AppCompatActivity
{

    @SuppressLint("ResourceType")
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //LinearLayout linearLayout = findViewById(R.id.GroupContainer);
        GridLayout Glyout;// = findViewById(R.id.Glayout_item);
        Glyout = (GridLayout)findViewById(R.id.id_grid) ;

        Glyout.setColumnCount(4);
        Glyout.setRowCount(20);
        int rowIndex = 0 ;



        // Create EditText
        for(int i = 0 ; i< 10 ; i++)
        {
            rowIndex     = i ;
            EditText editText = new EditText(this);
            GridLayout.LayoutParams param = new GridLayout.LayoutParams();
            param.height = 50;//ViewGroup.LayoutParams.WRAP_CONTENT;
            param.width = 250 ;// GridLayout.LayoutParams.MATCH_PARENT;
            param.rowSpec = GridLayout.spec(rowIndex);
            param.columnSpec = GridLayout.spec(0);

            param.setMargins(0,5,0,0);

            editText.setTextColor(R.color.colorPrimaryDark);
            editText.setTextSize(10);
            editText.setBackgroundColor(0xFFFFFFFF);
            editText.setLayoutParams(param);
            if (rowIndex == 1) {
                editText.setId( R.id.task1);
            }
            if (rowIndex == 2) {
               editText.setId(R.id.task2);
            }

            //editText.setHeight(30);
           // editText.setWidth(180);
           // editText.setBackgroundColor(R.color.colorAccent);
            Glyout.addView(editText);
            rowIndex++;
        }



   }


}

在此处输入图片描述

推荐答案

尝试将param.height = 50;设置为WRAP_CONTENT

// Create EditText
    for(int i = 0 ; i< 10 ; i++)
    {
        rowIndex     = i ;
        EditText editText = new EditText(this);
        GridLayout.LayoutParams param = new GridLayout.LayoutParams();
        param.height = WRAP_CONTENT;
        param.width = 250 ;// GridLayout.LayoutParams.MATCH_PARENT;
        param.rowSpec = GridLayout.spec(rowIndex);
        param.columnSpec = GridLayout.spec(0);

        param.setMargins(0,5,0,0);

        editText.setTextColor(R.color.colorPrimaryDark);
        editText.setTextSize(10);
        editText.setBackgroundColor(0xFFFFFFFF);
        editText.setLayoutParams(param);
        if (rowIndex == 1) {
            editText.setId( R.id.task1);
        }
        if (rowIndex == 2) {
           editText.setId(R.id.task2);
        }

        //editText.setHeight(30);
       // editText.setWidth(180);
       // editText.setBackgroundColor(R.color.colorAccent);
        Glyout.addView(editText);
        rowIndex++;
    }

这篇关于EditText,输入的文本不完整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆