2014-01-03 3 views
-1

Это мой текущий макет для моей ListViewКак я могу изменить свое расположение ListView в Android

enter image description here

Как я могу отобразить флаг слева, переместить слово вправо, и место страны в первый ряд, за которым следует ранг и население?

И как я могу добавить полосу прокрутки сбоку, чтобы она могла скользить вниз, чтобы увидеть все страны?

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <TextView 
     android:id="@+id/ranklabel" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/ranklabel" /> 

    <TextView 
     android:id="@+id/rank" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@+id/ranklabel" /> 

    <TextView 
     android:id="@+id/countrylabel" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/ranklabel" 
     android:text="@string/countrylabel" /> 

    <TextView 
     android:id="@+id/country" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/rank" 
     android:layout_toRightOf="@+id/countrylabel" /> 

    <TextView 
     android:id="@+id/populationlabel" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/countrylabel" 
     android:text="@string/populationlabel" /> 

    <TextView 
     android:id="@+id/population" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/country" 
     android:layout_toRightOf="@+id/populationlabel" /> 

    <ImageView 
     android:id="@+id/flag" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:background="#000000" 
     android:padding="1dp" /> 

</RelativeLayout> 

ответ

1
<ImageView 
     android:id="@+id/icon" 
     android:layout_width="22px" 
     android:layout_height="22px" 
     android:layout_marginLeft="4px" 
     android:layout_marginRight="10px" 
     android:layout_marginTop="4px" 
     android:src="@drawable/"Your Image" > 
    </ImageView> 

    <TextView 
     android:id="@+id/ranklabel" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/ranklabel" /> 

    <TextView 
     android:id="@+id/rank" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@+id/ranklabel" /> 

    <TextView 
     android:id="@+id/countrylabel" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/ranklabel" 
     android:text="@string/countrylabel" /> 

    <TextView 
     android:id="@+id/country" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/rank" 
     android:layout_toRightOf="@+id/countrylabel" /> 

    <TextView 
     android:id="@+id/populationlabel" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/countrylabel" 
     android:text="@string/populationlabel" /> 

    <TextView 
     android:id="@+id/population" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/country" 
     android:layout_toRightOf="@+id/populationlabel" /> 
0
<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" > 

    <ImageView 
     android:id="@+id/flag" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_centerVertical="true" 
     android:background="#000000" 
     android:padding="1dp" /> 

    <TextView 
     android:id="@+id/ranklabel" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@id/flag" 
     android:text="RANK" /> 

    <TextView 
     android:id="@+id/rank" 
     android:layout_width="wrap_content" 
     android:text=" 1" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@+id/ranklabel" /> 

    <TextView 
     android:id="@+id/countrylabel" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/ranklabel" 
     android:layout_toRightOf="@id/flag" 
     android:text="COUNTRY" /> 

    <TextView 
     android:id="@+id/country" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text=" England" 
     android:layout_below="@+id/rank" 
     android:layout_toRightOf="@+id/countrylabel" /> 

    <TextView 
     android:id="@+id/populationlabel" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/countrylabel" 
     android:layout_toRightOf="@id/flag" 
     android:text="POPULATION" /> 

    <TextView 
     android:id="@+id/population" 
     android:layout_width="wrap_content" 
     android:text=" 200 00" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/country" 
     android:layout_toRightOf="@+id/populationlabel" /> 

</RelativeLayout> 
2

Как я могу отобразить флаг слева, и переместите Слово к правильно? И поместите страну в качестве первого ряда, следуйте по рангу и Население?

=> Я предполагаю, что вы все знает о RelativeLayout, так что я хотел бы предложить вам попробовать себя некоторые атрибуты, как:

android:layout_below 
android:layout_toRightOf 

Как я могу добавить полосу прокрутки на стороне, так что он может скользить вниз до посмотреть всю страну?

=> Поскольку ListView сам по себе является прокручиваемым видом, вам не нужно использовать ScrollView.

0

В вашей относительной макете сделать свой ImageView в качестве первого ребенка и применять android:layout_toRightOf="@id/flag" в каждой из ваших ярлыках, лейблах

Или просто скопировать и вставить следующий код в XML

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <ImageView 
     android:id="@+id/flag" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="#000000" 
     android:padding="1dp"/> 

    <TextView 
     android:id="@+id/ranklabel" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@+id/flag" 
     android:text="@string/ranklabel" /> 

    <TextView 
     android:id="@+id/rank" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@+id/ranklabel" /> 

    <TextView 
     android:id="@+id/countrylabel" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/ranklabel" 
     android:layout_toRightOf="@+id/flag" 
     android:text="@string/countrylabel" /> 

    <TextView 
     android:id="@+id/country" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/rank" 
     android:layout_toRightOf="@+id/countrylabel" /> 

    <TextView 
     android:id="@+id/populationlabel" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@+id/flag" 
     android:layout_below="@+id/countrylabel" 
     android:text="@string/populationlabel" /> 

    <TextView 
     android:id="@+id/population" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/country" 
     android:layout_toRightOf="@+id/populationlabel" /> 

</RelativeLayout> 
Смежные вопросы