TextView and EditText in single line in Android?

I am writing XML as follows: list_item2 contains TextView and EditText, and list_item is another XML containing only TextView,

<?xml version="1.0" encoding="utf-8"?> 

 <TextView android:id="@+id/textItem" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="10dp" android:textSize="16sp" > </TextView> <EditText android:id="@+id/editText1" android:layout_width="fill_parent" android:layout_height="wrap_content" > </EditText> 

I am using xml in ListView for example

 public View getView(int position, View convertView, ViewGroup parent) { View row; if(position!=2) { LayoutInflater inflater = getLayoutInflater(); row = inflater.inflate(R.layout.list_item, parent, false); } else { LayoutInflater inflater = getLayoutInflater(); row = inflater.inflate(R.layout.list_item2, parent, false); } TextView tv = (TextView) row.findViewById(R.id.textItem); tv.setText(getItem(position)); tv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub } }); 

but it creates a conclusion like

  TextView EditText 

I want both on the same line for example

  TextView EditText 

Anyone is editing XML and let me know the hierarchy for creating a graphical interface in Android applications.

+4
source share
5 answers

Take the EditText and TextView inside the LinearLayout with a horizontal orientation (which is the default) and set layout_weight = 1 or whatever you want to EditText and TextView

 <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:id="@+id/textItem" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:padding="10dp" android:textSize="16sp" /> <EditText android:id="@+id/editText1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"/ > </LinearLayout> 
+11
source

use the following layout

 <?xml version="1.0" encoding="utf-8"? <LinearLayout android:id="@+id/lnrTitle" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:id="@+id/textItem" android:layout_width="fill_parent" android:layout_height="wrap_content" android:weight="1" android:textSize="16sp" > </TextView> <EditText android:id="@+id/editText1" android:layout_width="fill_parent" android:weight="1" android:layout_height="wrap_content" > </EditText> </LinearLayout> 
+2
source

Add one parent layout, say LinearLayout in your xml, like this:

 <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" > <TextView android:id="@+id/textItem" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="10dp" android:textSize="16sp" > </TextView> <EditText android:id="@+id/editText1" android:layout_width="fill_parent" android:layout_height="wrap_content" > </EditText> </LinearLayout> 
+1
source
  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" android:gravity="center" android:padding="10dp"> <TextView android:id="@+id/textItem" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="10dp" android:textSize="16sp" > </TextView> <EditText android:id="@+id/editText1" android:layout_width="fill_parent" android:layout_height="wrap_content" > </EditText> </LinearLayout> 
+1
source

Good and fast decision made by many applications today, add these tags to your TextView

 android:ellipsize="end" android:maxLines="1" 

Now your text is a single line with three dots to the end.

0
source

Source: https://habr.com/ru/post/1388259/


All Articles