的開始,我跟着這段代碼由奧比在另一個問題寫:https://stackoverflow.com/a/22682248/5915747滾動型被切斷文本
我的文初被切斷我的屏幕的左側。我錯過了相當多的信息,不知道如何解決它,我已經嘗試了一切爲別人工作,但它沒有爲我工作。
popup.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollviewtest"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
tools:context="com.info.PopupActivity"
android:background="#f0f0f0"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:id="@+id/rel_layout"
android:orientation="vertical">
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/table_layout"
android:background="#80000000"
android:layout_centerHorizontal="true">
</TableLayout>
</RelativeLayout>
</HorizontalScrollView>
</ScrollView>
init方法:
public void init() {
View popupview = getLayoutInflater().inflate(R.layout.popup, null);
popupWindow = new PopupWindow(
popupview, LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT
);
popupWindow.showAtLocation(popupview, Gravity.CENTER, 0, 0);
popup_shown[0] = true;
TableLayout tableLayout = (TableLayout) popupview.findViewById(R.id.table_layout);
TableRow row0 = new TableRow(this);
TextView text0 = new TextView(this);
text0.setText("Test Header1");
row0.addView(text0);
TextView text1 = new TextView(this);
text1.setText("Test Header2");
row0.addView(text1);
TextView text2 = new TextView(this);
text2.setText("Teset Header3");
row0.addView(text2);
TextView text3 = new TextView(this);
text3.setText("Test Header4");
row0.addView(text3);
TextView text4 = new TextView(this);
text4.setText("Test Header5");
row0.addView(text4);
tableLayout.addView(row0);
for (int i = 0; i < 8; i++) {
TableRow tableRow = new TableRow(this);
TextView tv0 = new TextView(this);
tv0.setGravity(Gravity.CENTER);
tv0.setText("long test field 0");
tableRow.addView(tv0);
TextView tv1 = new TextView(this);
tv1.setGravity(Gravity.CENTER);
tv1.setText("long test field 1");
tableRow.addView(tv1);
TextView tv2 = new TextView(this);
tv2.setGravity(Gravity.CENTER);
tv2.setText("long test field 2");
tableRow.addView(tv2);
TextView tv3 = new TextView(this);
tv3.setGravity(Gravity.CENTER);
tv3.setText("long test field 3");
tableRow.addView(tv3);
TextView tv4 = new TextView(this);
tv4.setGravity(Gravity.CENTER);
tv4.setText("long test field 3");
tableRow.addView(tv4);
tableLayout.addView(tableRow);
}
}
的字符串文本意見的時間越長,越作物了,但是這是一個水平滾動視圖,所以它應該只是從屏幕開始處開始並將長度添加到可滾動的結尾,對不對?
這是它結束了在垂直/縱向看起來像當前字符串: Vertical View
這就是它看起來像在水平,這似乎解決,因爲我的屏幕大足夠的數據: Horizontal View
如果您有任何問題,請詢問!
通過向滾動視圖添加填充來解決此問題。這似乎是一個常見的Android錯誤。
也許添加一些填充:d – Vucko