2017-03-03 126 views
0

我刚刚开始使用Android.This是我的第一个项目。我使用了列表视图来并排显示EditTextTextView。现在我想,如果我使用的是Button鉴于它正在对每EditText instead.The下面显示的是我的XML文件在end.But提交按钮:对齐按钮

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="horizontal" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 
<TextView 
    android:id="@+id/txtview" 
    android:text="subject" 
    android:layout_width="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:paddingLeft="10dp" 
    android:textSize="25dp" 
    android:textColor="@color/black" 
    android:layout_height="wrap_content" 
    android:layout_weight="0.7" 
    android:paddingRight="20dp" 
    android:textStyle="bold" 
    /> 
<EditText 
    android:cursorVisible="true" 
    android:id="@+id/ScanText" 
    android:hint="Internal+External" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="0.3" 
    android:layout_toRightOf="@id/textView" 
    android:inputType="number" 
    android:layout_marginTop="20dp" 
    /> 
<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Submit" 
    android:layout_alignParentEnd="true" 
    android:id="@+id/submitbutton"/> 
</RelativeLayout> 

这是该adapterListView用途的布局。该按钮也被显示为有TextView s.So我怎么能只显示在bottom.I一个按钮了输出below.But我只需要在底部

this is the output i got

一个提交按钮多次

我甚至试过把对接在我main activity下面ListView。但它did'nt下面work.The是我的XML:

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="wrap_content" 
android:layout_height="match_parent" 

> 
<ListView 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:id="@android:id/list"></ListView> 

<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Submit" 

    android:id="@+id/submitbutton"/> 


</LinearLayout> 
+0

显示您预期的输出! –

+4

从此布局中删除按钮,此布局用于列表项目。将你的按钮添加到包含listView的布局中。 –

+2

将按钮放在活动布局中 - 而不是每次都要创建按钮 – rafsanahmad007

回答

0

你可以尝试改变:

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="wrap_content" 
android:layout_height="match_parent" 

> 
<ListView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@android:id/list"></ListView> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Submit" 

     android:id="@+id/submitbutton"/> 


    </LinearLayout> 

(因为match_parent改变layout_height成WRAP_CONTENT ,它会占用所有的地方,所以没有更多的地方为您的按钮)

我是一种新的android也是如此尝试这一点。

,如果它不能正常工作,尝试加入这一行:

android:layout_weight="1" 

您的ListView

+0

@dupuis不工作 –

0
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    > 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     > 

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

     <Button 
      android:id="@+id/submitbutton" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="submit" 
      /> 
    </LinearLayout> 

</LinearLayout> 
+0

像魔术一样工作!谢谢dhanvani –

+0

欢迎,你也可以投我。 @kishoreKumar –