2011-04-23 4 views
0

나는 이것을 간단하게 알고있다. 그것은 나에게 미쳤다. 나는이보고를 좋게하기 위해 너무 많은 허튼 소리를 시도했다. 그리고 아무것도 작동하지 않고있다!! :매우 단순한 안드로이드 레이아웃

높이 왼쪽에 넣어되는 이미지와 동일한와 고정 된 헤더 : 나는 레이아웃은 다음과 같이 할

:/여기

내 문제입니다. 이미지의 오른쪽에는 2 줄에 걸쳐있을 가능성이있는 단순한 텍스트가 필요합니다. 고정 된 헤더 아래

, 나는 약간의 같은 테이블 레이아웃의 종류가 필요합니다

---------------------------------- 
Birth date  |  09/23/1945 
---------------------------------- 
Death date  |  04/27/2011 
---------------------------------- 

등 해당 행 중 하나에서

를, 텍스트가있는 내용에 따라 두 줄에 걸쳐 수 데이터 베이스. 첫 번째 열의 텍스트는 모두 정적이며 두 번째 열의 텍스트는 동적입니다. 테이블 행은 많은 정보를 저장할 수 있도록 ScrollView (쉬운 부분)에 넣어야합니다. 나는 TableLayout을 사용해 보았고 모든 종류의 두통을 겪어왔다. 또한 고정 헤더의 경우 layout_below 이상으로 RelativeLayout 전체를 사용하여 작동하도록했지만 이미지 간격과 텍스트를 올바르게 맞출 수는 없습니다. 그것은 두통입니다! 어떤 도움을 주셔서 감사합니다!

+1

당신이 많이있는 경우에 당신은 확실히, 사용자 정의 어댑터와 함께 사용자 지정 목록보기 항목을 사용한다 동적 행 – bigstones

답변

3

글쎄, 나는보고 해야하는 방법을 100 % 이해하지만 당신은 좀 더 주면 당신이 둥지 레이아웃, 당신은 아마 더 도움이 될 수 있습니다

<LinearLayout 
    orientation="vertical" 
    width="match_parent" 
    height="wrap_content"> 

    <!-- header --> 
    <LinearLayout 
     orientation="horizontal" 
     width="match_parent" 
     height="wrap_content"> 

     <ImageView 
      width="wrap_content" 
      height="wrap_content"> 
     <TextView 
      width="match_parent" 
      height="wrap_content" 
      lines="2"> 
    </LinearLayout> 

    <!-- Table here. You can use either TableLayout or nested LinearLayouts. 
     I prefer LinearLayouts. They have also a nice feature: 
     <LinearLayout> 
      <View width="match_parent" weight="1" /> 
      <View width="match_parent" weight="1" /> 
     </LinearLayout> 
     ...makes both views equally wide, which you can use in your table. --> 
</LinearLayout> 

같은 것을 사용할 수 있습니다 수 있음을 기억하지 않는다 발생하는 문제에 대한 정보.

는 bigstones [편집] ... 또는 그의 의견에 말한다 - 대신 테이블의 사용자 정의 어댑터 목록보기 사용할 수있는, 즉

+0

정말 고마워 ..... 나는 그게 효과가있어! :) – SpellChucker

1

여기 내가 무슨 아마 훨씬 더 나은 솔루션 :)입니다.

row.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center_vertical"> 
    <TextView 
     android:id="@+id/left_text" 
     android:layout_width="75dip" 
     android:layout_height="wrap_content" /> 
    <TextView 
     android:id="@+id/right_text" 
     android:layout_width="0dip" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:maxLines="2" 
     android:ellipsize="end" /> 
</LinearLayout>

홈페이지 앱

public class Main extends Activity 
{ 
    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    List<Datum> data = new ArrayList<Datum>(); 
    data.add(new Datum("FIRST", "One line of text.")); 
    data.add(new Datum("SECOND", "Two lines of text. Two lines of text. Two lines of text.")); 
    data.add(new Datum("THIRD", "Three or more lines of text. Three or more lines of text. Three or more lines of text. Three or more lines of text. Three or more lines of text. Three or more lines of text.")); 
    data.add(new Datum("FOURTH", "One line of text, again.")); 

    ListView leftList = (ListView) findViewById(R.id.my_list); 
    leftList.setAdapter(new MyAdapter(this, R.layout.row, data)); 
    } 
} 

class Datum 
{ 
    String left, right; 

    Datum(String left, String right) 
    { 
    this.left = left; 
    this.right = right; 
    } 
} 

class MyAdapter extends ArrayAdapter<Datum> 
{ 
    List<Datum> data; 
    int textViewResourceId; 

    MyAdapter(Context context, int textViewResourceId, List<Datum> data) 
    { 
    super(context, textViewResourceId, data); 
    this.data = data; 
    this.textViewResourceId = textViewResourceId; 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) 
    { 
    if (convertView == null) 
    { 
     LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     convertView = inflater.inflate(textViewResourceId, null); 
    } 
    Datum datum = data.get(position); 
    if (datum != null) 
    { 
     TextView leftView = (TextView) convertView.findViewById(R.id.left_text); 
     TextView rightView = (TextView) convertView.findViewById(R.id.right_text); 
     if (leftView != null) 
     { 
     leftView.setText(datum.left); 
     } 
     if (rightView != null) 
     { 
     rightView.setText(datum.right); 
     } 
    } 
    return convertView; 
    } 
}