2013-07-10 4 views
2

First ImageSecond ImageПросмотр списка полной вид

Я новый андроид развития. Ниже я прикрепляю свой файл макета.

В моем расположении у меня есть один ListView и один EditText с ImageButton. Когда я вставляю задачу в EditText и нажимаю ImageButton, эта задача будет добавлена ​​в ListView одна за другой.

Моя проблема предположит, что я добавить более 4 задачи означает, что EditText с ImageButton зрения не виден, потому что элементы списка, которые принимают place.I добавить свой снимок экрана выше их просьбе дать решение спасибо ...

`**Layout:**   
     <?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:weightSum="3" > 

     <Button 
      android:id="@+id/todaytaskbtnid" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="0dip" 
      android:layout_height="wrap_content" 
      android:layout_gravity="left" 
      android:layout_weight="1" 
      android:background="@drawable/buttonselector" 
      android:text="TODAY" /> 

     <Button 
      android:id="@+id/tomorrowtaskbtnid" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="0dip" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:background="@drawable/buttonselector" 
      android:text="TOMORROW" /> 

     <Button 
      android:id="@+id/futuretaskbtnid" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="0dip" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:background="@drawable/buttonselector" 
      android:text="FUTURE" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <ListView 
      android:id="@+id/frontpagetasklistid" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 
     </ListView> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom" > 

     <RelativeLayout 
      android:id="@+id/relativelayoutid" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom" > 

      <EditText 
       android:id="@+id/edittextidAddTodayTask" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
       android:background="@drawable/edittextselector" 
       android:hint="Add Today Task" /> 

      <ImageButton 
       android:id="@+id/imagebuttonidAddTodayTask" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
       android:layout_alignParentRight="true" 
       android:layout_gravity="right" 
       android:src="@drawable/addtask" /> 
     </RelativeLayout> 
    </LinearLayout> 

</LinearLayout> 
+0

Вы не должны жёстко высоту ListView вместо заставить его используйте оставшееся пространство на экране. – user818455

+0

Будет работать в RelativeLayout (который может быть использован, конечно), но как это сделать в линейной компоновке? –

ответ

2

У вас может быть один Relative layout или вы можете попробовать следующее. Вы можете иметь один относительный макет и размещать свои виджеты относительно друг друга.

Другой вариант заключается в добавлении виджета кнопки linearlayout в виде заголовка. Также добавьте кнопку editext и изображения в качестве нижнего колонтитула в список.

<Button 
     android:id="@+id/todaytaskbtnid" 
     style="?android:attr/buttonStyleSmall" 
     android:layout_width="0dip" 
     android:layout_height="wrap_content" 
     android:layout_gravity="left" 
     android:layout_weight="1" 
     android:background="@drawable/ic_launcher" 
     android:text="TODAY" /> 

    <Button 
     android:id="@+id/tomorrowtaskbtnid" 
     style="?android:attr/buttonStyleSmall" 
     android:layout_width="0dip" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:background="@drawable/ic_launcher" 
     android:text="TOMORROW" /> 

    <Button 
     android:id="@+id/futuretaskbtnid" 
     style="?android:attr/buttonStyleSmall" 
     android:layout_width="0dip" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:background="@drawable/ic_launcher" 
     android:text="FUTURE" /> 
</LinearLayout> 
    <ListView 
      android:id="@+id/frontpagetasklistid" 
      android:layout_above="@+id/edittextidAddTodayTask" 
      android:layout_below="@+id/ll" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" > 

     </ListView> 
     <EditText 
      android:id="@+id/edittextidAddTodayTask" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:background="@drawable/ic_launcher" 
      android:hint="Add Today Task"/> 

     <ImageButton 
      android:id="@+id/imagebuttonidAddTodayTask" 
      android:layout_width="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentRight="true" 
      android:layout_height="wrap_content" 
      android:layout_gravity="right" 
      android:src="@drawable/ic_launcher" /> 
    </RelativeLayout> 

Edit: с помощью одного относительного расположения

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:id="@+id/rl" 
tools:context=".MainActivity" > 


    <ListView 
      android:id="@+id/frontpagetasklistid" 
      android:layout_above="@+id/edittextidAddTodayTask" 
      android:layout_below="@+id/button1" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" > 

     </ListView> 

     <ImageButton 
      android:id="@+id/imagebuttonidAddTodayTask" 
      android:layout_width="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentRight="true" 
      android:layout_height="wrap_content" 
      android:layout_gravity="right" 
      android:src="@drawable/ic_launcher" /> 

     <Button 
      android:id="@+id/button1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentTop="true" 
      android:text="Button" /> 

     <Button 
      android:id="@+id/button2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignBottom="@+id/button1" 
      android:layout_centerHorizontal="true" 
      android:text="Button" /> 

     <Button 
      android:id="@+id/button3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignBaseline="@+id/button2" 
      android:layout_alignBottom="@+id/button2" 
      android:layout_alignRight="@+id/frontpagetasklistid" 
      android:layout_marginRight="11dp" 
      android:text="Button" /> 

     <EditText 
      android:id="@+id/edittextidAddTodayTask" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_alignRight="@+id/imagebuttonidAddTodayTask" 

      android:ems="10" 
      android:hint="Add Today Task" /> 

    </RelativeLayout> 

Grpahical экрана редактор выстрела

enter image description here

Samsung Galaxy s3 снимка экрана

! [Введите описание изображения здесь] [2]

Поскольку вы попросили forscreen снимок, добавив несколько элементов

! [Введите описание изображения здесь] [3]

![enter code here][1] 

Из обсуждения

Have row.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="38dp" 
     android:text="TextView" /> 

</RelativeLayout> 

MainActivity.java

Вы можете использовать первый XML в качестве activity_main.xml

public class MainActivity extends Activity { 
    EditText ed; 
    ImageButton ib; 
    ListView lv; 
    ArrayList<String> aa; 
    ArrayAdapter<String> arrayAdapter; 
    CustomAdapter cus; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     ed= (EditText) findViewById(R.id.edittextidAddTodayTask); 
     ib= (ImageButton) findViewById(R.id.imagebuttonidAddTodayTask); 
     aa = new ArrayList<String>(); 
     lv= (ListView) findViewById(R.id.frontpagetasklistid); 
     for(int i=0;i<100;i++) 
     { 
      aa.add(""+i); 
     } 
     cus = new CustomAdapter(); 
     //arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, aa); 
     lv.setAdapter(cus); 
     ib.setOnClickListener(new OnClickListener() 
     { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       Log.i("...............", "..............."); 
       aa.add(ed.getText().toString()); 
       cus.notifyDataSetChanged(); 

      } 

     }); 
    } 

    class CustomAdapter extends BaseAdapter 
    { 
     LayoutInflater mInflater; 
     TextView tv; 
     public CustomAdapter() 
     { 
      this.mInflater = LayoutInflater.from(MainActivity.this); 
     } 
    @Override 
    public int getCount() { 
     // TODO Auto-generated method stub 
     return aa.size(); 
    } 

    @Override 
    public Object getItem(int position) { 
     // TODO Auto-generated method stub 
     return null; 
    } 

    @Override 
    public long getItemId(int position) { 
     // TODO Auto-generated method stub 
     return 0; 
    } 

    public View getView(int arg0, View arg1, ViewGroup arg2) { 

     if(arg1==null) 
     { 
      arg1=mInflater.inflate(R.layout.row, arg2,false); 
     } 
      tv= (TextView) arg1.findViewById(R.id.textView1); 
      tv.setText(aa.get(arg0)); 


     return arg1; 
     } 

    } 

} 
+0

gonna edit the post din't см. Отредактированный вопрос – Raghunandan

+0

только я редактирую мой просмотр списка height wrap_content. – Satheesh

+0

@Satheesh попробуйте вышесказанное, и вы можете иметь один относительный макет для повышения эффективности. – Raghunandan

1

я внести некоторые изменения в макете:

<?xml version="1.0" encoding="utf-8"?> 
     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical" 
      android:weightSum="10"> 

      <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="0dip" 
      android:layout_weight="1" 
      android:weightSum="30" 
      android:orientation="horizontal" 
      > 
      <Button 
       android:layout_height="fill_parent" 
       android:layout_width="0dip" 
       android:layout_weight="10" 
       /> 
      <Button 
       android:layout_height="fill_parent" 
       android:layout_width="0dip" 
       android:layout_weight="10" 
       /> 
      <Button 
       android:layout_height="fill_parent" 
       android:layout_width="0dip" 
       android:layout_weight="10" 
       /> 
      </LinearLayout> 
     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="0dip" 
      android:layout_weight="8" 
      > 

      <ListView 
       android:id="@+id/frontpagetasklistid" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" > 

      </ListView> 
      </LinearLayout> 

      <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="0dip" 
      android:layout_weight="1" 
      android:weightSum="10" 
      android:orientation="horizontal" 
      > 

      <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="0dip" 
      android:layout_weight="1" 

      android:orientation="horizontal" 
      > 

      <EditText 
       android:id="@+id/edittextidAddTodayTask" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:hint="Add Today Task" 
       android:layout_weight="10" 
       android:drawableRight="@drawable/ic_launcher" 
       android:background="@android:color/black" 
       /> 
    /// I remove the button . there is no need of it. 
      </LinearLayout> 


     </LinearLayout> 

enter image description here

Теперь вызовите ваш drawableRight клик для обработки действия

yourEditText.setOnTouchListener(new RightDrawableOnTouchListener(keyword) { 
     @Override 
     public boolean onDrawableTouch(final MotionEvent event) { 
      // do whatever you want 
     } 
    }); 
+0

см. Может отредактировать макет с тремя кнопками сверху – KDeogharkar

+0

Но мой образный образ находится в edittext в конце позиции, так как ее возможно, пожалуйста, дайте ..... – Satheesh

+0

set android: drawableRight = "@ drawable/your_icon" внутри вашего текста текстового свойства – KDeogharkar

1

Вы можете использовать listView.addFooterView (view); Здесь вид относится к представлению, содержащему текст редактирования и кнопку добавления.

+0

Я также пытаюсь это, но та же проблема возникает – Satheesh

1

Вы можете добавить footerview в listview и сделать его невидимым. В нижнем колонтитуле скопируйте макет нижней панели, которая включает EditText и ImageButton. Просто создайте новый файл макета и вставьте этот xml в файл.

<RelativeLayout 
       android:id="@+id/relativelayoutid" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:visibility="invisible" > 

       <EditText 
        android:id="@+id/edittextidAddTodayTask" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:background="@drawable/edittextselector" 
        android:hint="Add Today Task" /> 

       <ImageButton 
        android:id="@+id/imagebuttonidAddTodayTask" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentBottom="true" 
        android:layout_alignParentRight="true" 
        android:layout_gravity="right" 
        android:src="@drawable/addtask" /> 
      </RelativeLayout> 

Добавить этот макет как footerview в свой список. Таким образом, ваш Listview никогда не скроет исходную нижнюю панель. Не забудьте сделать его невидимым.

1

Привет, пожалуйста, попробуйте использовать вес для просмотра списка

Пример путем редактирования XML является:

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

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:weightSum="3" > 

    <Button 
     android:id="@+id/todaytaskbtnid" 
     style="?android:attr/buttonStyleSmall" 
     android:layout_width="0dip" 
     android:layout_height="wrap_content" 
     android:layout_gravity="left" 
     android:layout_weight="1" 
     android:background="@drawable/buttonselector" 
     android:text="TODAY" /> 

    <Button 
     android:id="@+id/tomorrowtaskbtnid" 
     style="?android:attr/buttonStyleSmall" 
     android:layout_width="0dip" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:background="@drawable/buttonselector" 
     android:text="TOMORROW" /> 

    <Button 
     android:id="@+id/futuretaskbtnid" 
     style="?android:attr/buttonStyleSmall" 
     android:layout_width="0dip" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:background="@drawable/buttonselector" 
     android:text="FUTURE" /> 
</LinearLayout> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <ListView 
     android:id="@+id/frontpagetasklistid" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1"> 
    </ListView> 

    <RelativeLayout 
     android:id="@+id/relativelayoutid" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom" > 

     <EditText 
      android:id="@+id/edittextidAddTodayTask" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:background="@drawable/edittextselector" 
      android:hint="Add Today Task" /> 

     <ImageButton 
      android:id="@+id/imagebuttonidAddTodayTask" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentRight="true" 
      android:layout_gravity="right" 
      android:src="@drawable/addtask" /> 
    </RelativeLayout> 
</LinearLayout> 

Смежные вопросы