解决方案 »

  1.   

    用个ScrollView把你的“名称1”的TextView包裹住试试
      

  2.   

    一楼貌似可以,但是ScrollView包LinearLayout
      

  3.   

    我尝试过一楼的做法,ScrollView包裹LinearLayout和TextView都可以。但是都没有效果。
      

  4.   


    你布局没弄好,你试试 我改写的你的XMLactivitypackage app.example.test0116;import android.os.Bundle;
    import android.widget.TextView;
    import android.app.Activity;public class MainActivity extends Activity { @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    TextView tv = (TextView) findViewById(R.id.tvShow);
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < 1000; i++) {
    sb.append("阿股份放松放松法AF");
    }
    sb.append("结束");
    tv.setText(sb.toString());
    }}XML
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >    <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >        <Button
                android:id="@+id/button_plan_year"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:background="#990033"
                android:focusable="true"
                android:gravity="center"
                android:text="上1" />        <Button
                android:id="@+id/button_plan_month"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:background="#006633"
                android:gravity="center"
                android:text="上2" />        <Button
                android:id="@+id/button_plan_week"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:background="#cccc00"
                android:gravity="center"
                android:text="上3" />        <Button
                android:id="@+id/button_plan_day"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:background="#666666"
                android:gravity="center"
                android:text="上4" />
        </LinearLayout>    <ImageView
            android:layout_width="fill_parent"
            android:layout_height="1dp"
            android:background="#cc3366" />    <ImageView
            android:layout_width="fill_parent"
            android:layout_height="1dp"
            android:background="#333399" />    <ScrollView
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="#C7F5F8" >        <TextView
                android:id="@+id/tvShow"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="#C7F5F8"
                android:gravity="left"
                android:text="名称1"
                android:textColor="#aa0000" />
        </ScrollView>    <ImageView
            android:layout_width="fill_parent"
            android:layout_height="1dp"
            android:background="#FF0033" />    <ImageView
            android:layout_width="fill_parent"
            android:layout_height="1dp"
            android:background="#0099cc" />    <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >        <Button
                android:id="@+id/button_plan"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#33cc99"
                android:gravity="center"
                android:text="下1" />        <Button
                android:id="@+id/button_new"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#ffffcc"
                android:gravity="center"
                android:text="下2" />        <Button
                android:id="@+id/button_my"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#99ccff"
                android:gravity="center"
                android:text="下3" />
        </LinearLayout></LinearLayout>
      

  5.   


    你布局没弄好,你试试 我改写的你的XMLactivitypackage app.example.test0116;import android.os.Bundle;
    import android.widget.TextView;
    import android.app.Activity;public class MainActivity extends Activity { @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    TextView tv = (TextView) findViewById(R.id.tvShow);
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < 1000; i++) {
    sb.append("阿股份放松放松法AF");
    }
    sb.append("结束");
    tv.setText(sb.toString());
    }}XML
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >    <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >        <Button
                android:id="@+id/button_plan_year"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:background="#990033"
                android:focusable="true"
                android:gravity="center"
                android:text="上1" />        <Button
                android:id="@+id/button_plan_month"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:background="#006633"
                android:gravity="center"
                android:text="上2" />        <Button
                android:id="@+id/button_plan_week"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:background="#cccc00"
                android:gravity="center"
                android:text="上3" />        <Button
                android:id="@+id/button_plan_day"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:background="#666666"
                android:gravity="center"
                android:text="上4" />
        </LinearLayout>    <ImageView
            android:layout_width="fill_parent"
            android:layout_height="1dp"
            android:background="#cc3366" />    <ImageView
            android:layout_width="fill_parent"
            android:layout_height="1dp"
            android:background="#333399" />    <ScrollView
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="#C7F5F8" >        <TextView
                android:id="@+id/tvShow"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="#C7F5F8"
                android:gravity="left"
                android:text="名称1"
                android:textColor="#aa0000" />
        </ScrollView>    <ImageView
            android:layout_width="fill_parent"
            android:layout_height="1dp"
            android:background="#FF0033" />    <ImageView
            android:layout_width="fill_parent"
            android:layout_height="1dp"
            android:background="#0099cc" />    <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >        <Button
                android:id="@+id/button_plan"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#33cc99"
                android:gravity="center"
                android:text="下1" />        <Button
                android:id="@+id/button_new"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#ffffcc"
                android:gravity="center"
                android:text="下2" />        <Button
                android:id="@+id/button_my"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#99ccff"
                android:gravity="center"
                android:text="下3" />
        </LinearLayout></LinearLayout>

    我看了下,你修改的地方就是以下这部分是吧(将ScrollView的高度设置为0dp,然后TextView的text赋值删掉)?然后TextView的文本赋值写在了对应的Activity文件内。请问,如果这样写,当文本内容过多时,就不会出现影响界面布局的问题了嘛?因为我需要晚上回家才能验证你的这个做法,所以想先问清楚。
    <ScrollView
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="#C7F5F8" >
     
            <TextView
                android:id="@+id/tvShow"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="#C7F5F8"
                android:gravity="left"
                android:text="名称1"
                android:textColor="#aa0000" />
        </ScrollView>
      

  6.   

    这个地方也有变化哈,还有就是TextView的文本赋值在哪儿并不影响。我自己验证过 不得出现你说的影响界面布局的问题了     <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >
     
            <Button
                android:id="@+id/button_plan"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#33cc99"
                android:gravity="center"
                android:text="下1" />
     
            <Button
                android:id="@+id/button_new"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#ffffcc"
                android:gravity="center"
                android:text="下2" />
     
            <Button
                android:id="@+id/button_my"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#99ccff"
                android:gravity="center"
                android:text="下3" />
        </LinearLayout>
      

  7.   

            我懂你的写法了,在http://www.cnblogs.com/zhmore/archive/2011/11/04/2236514.html网址看到的具体分析。但是我还有点没明白。
            你把ScrollView内的TextView的height改为0dp,这样就可以正常显示了,但是下方的LinearLayout内的button的width值也为0dp?能帮解释下嘛?我没看懂。
      

  8.   

    LinearLayout内部的控件如果该LinearLayout为垂直方向,那么如果要按比率放置它的位置,你可以写它的weight,并且设置它的高度为0dp,如果该LinearLayout为水平方向,那么如果要按比率放置它的位置,你可以写它的weight,并且设置它的宽度为0dp。
    你如果还要设置滑动,你可以LinearLayout嵌套加上个ScrollView,设置ScrollView的weight、宽或高。在ScrollView的里面的控件可以设置任意高度或宽度。
      

  9.   

    如你所见这个线性布局的width为填充满水平方向且orientation="horizontal",这就意味着该线性布局里面的子控件如果只有一个的话,即使width=0dp,只要weight="1"也将填满整个水平方向。再举一个简单的,现在假设你的手机width=400dp且这个线性布局里面有两个Button,其中一个width=50dp并未设置weight,而另一个width=0dp,weight="1"。那么你看到的效果将是第一个Button占了手机width=50dp,第二个Button占了手机width=350dp。总之设置weight的大概用意就是你们剩下不要的空间都给我。假设现在又有第三个Button:width=50dp并未设置weight。那么你看到的效果将是第一个Button占了手机width=50dp,第二个Button占了手机width=300dp,第三个Button占了手机width=50dp。假设现在又有第四个Button:width=0dp,weight="1"。那么你看到的效果将是第一个Button占了手机width=50dp,第二个Button占了手机width=100dp,第三个Button占了手机width=50dp,第四个Button占了手机width=100dp最后你会发现大家weight值一样时会平分所剩空间比例。而weight值越小分的越多
    <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >
      
            <Button
                android:id="@+id/button_plan"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#33cc99"
                android:gravity="center"
                android:text="下1" />
      
            <Button
                android:id="@+id/button_new"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#ffffcc"
                android:gravity="center"
                android:text="下2" />
      
            <Button
                android:id="@+id/button_my"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#99ccff"
                android:gravity="center"
                android:text="下3" />
        </LinearLayout>