English 中文(简体)
在表Layout内安装线索的问题
原标题:Problem with placing a LinearLayout inside a TableLayout

在我看来,试图树立形象和一些文字,其形象是案文高度的两倍,这样,文本的两行就能够贴上形象,就像这样:

 _____
|     |text here
|_____|text here

试图这样做的办法是将两条文本放在“线性语言”中,然后将《图像》和含有文字的“线性语言”放在一个行文和两个栏目上。

仅凭《图像评论》才这样做。 事实上,即便在我评论在表格中添加《图像评论》时,“线索”内的案文也完全得到了展示。

非常赞赏对守则的任何帮助或对布局的不同做法。

LinearLayout tempVindLayout = new LinearLayout(this);
    tempVindLayout.setOrientation(LinearLayout.VERTICAL);
    tempVindLayout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    TableLayout tabellLayout = new TableLayout(this);
    tabellLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    tabellLayout.setPadding(0, 60, 0, 0);

    TableRow row1 = new TableRow(this);
    row1.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

    // Textview saturday
    TextView tempSat = new TextView(this);
    tempSat.setText("+13");
    tempSat.setTextAppearance(this, R.style.RegularSmall);
    tempSat.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

    // Wind saturday
    TextView vindSat = new TextView(this);
    vindSat.setText("5 m/s");
    vindSat.setTextAppearance(this, R.style.RegularSmall);
    vindSat.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

    //Image for weather icons
    ImageView imgSat = new ImageView(this);
    imgSat.setImageResource(R.drawable.solmoln);
    imgSat.setAdjustViewBounds(true);

    // Add to table
    tempVindLayout.addView(tempSat);
    tempVindLayout.addView(vindSat);

    row1.addView(tempVindLayout);
    row1.addView(imgSat);

    tabellLayout.addView(row1);

    setContentView(tabellLayout);
问题回答

可以通过下列布局实现类似目标......

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
<ImageView android:id="@+id/ImageView_01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/image" />
<RelativeLayout 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_toRightOf="@+id/ImageView_01">
    <TextView android:id="@+id/TextView_01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Header Text"
        android:textColor="@android:color/white"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Header Text"
        android:textColor="@android:color/white"
        android:layout_below="@+id/TextView_01"/>
    </RelativeLayout>
</RelativeLayout>

或许这样一些事情是有益的:

<?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="horizontal" >

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_launcher" />

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceMedium" />

</LinearLayout>





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签