我正在使用这个代码
public class MainActivity extends Activity {
TextView textview;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String hallo = "blabla " + "jojo " + "lol " + "\n" + "doj " + "drasl " + "\n";
InputStream is = new ByteArrayInputStream(hallo.getBytes());
BufferedReader in = new BufferedReader(new InputStreamReader(is));
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.linearLayout);
String line;
try {
while ((line = in.readLine()) != null) {
String[] RowData = line.split(" ");
String eitt = RowData[0];
String tvo = RowData[1];
TextView textView = new TextView(this);
textView.setText(line);
textView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT
,LayoutParams.WRAP_CONTENT));
linearLayout.addView(textView);
}
} catch (IOException e1) {
e1.printStackTrace();
}
}
}使用下面的xml代码
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>我希望将字符串的这些部分插入到表格布局中,以便在打印文本时,它们会以漂亮的列出现。它的工作方式是,它只打印字符串行,而不是将其放入列中。同样重要的是,我不知道字符串中有多少行,所以我不能只制作4个文本视图框,因为可能有50到100行,所以我需要在表视图中创建i个文本视图框,i是行数。但是我总是收到这个错误,调用需要api级别11,而我使用的是api级别10。
textView.setLayoutParams(newLayoutParams(LayoutParams.FILL_PARENT
,LayoutParams.WRAP_CONTENT));我可以使用什么样的参数布局选项来让它工作。
发布于 2014-03-19 07:34:27
您没有显示导入,但是您可能使用了错误的LayoutParams导入(就像猫咪建议的那样)。看起来您可能想要使用下面的导入。
import android.view.ViewGroup.LayoutParams;发布于 2013-11-10 20:30:17
我也有同样的问题。仔细检查您的导入,以确保您没有导入不适当的LayoutParams。我最终在应该是LinearLayout.LayoutParams的时候导入了一些随机的东西,比如Actionbar.LayoutParams。
https://stackoverflow.com/questions/13251089
复制相似问题