Reputation: 8732
here is the problem. I have a listview and a bunch of array-strings. I want to fill the listview with one textview for each string. the strings are injected but after injection the layout does not repsect the one that I have defined in tip_row.xml (in particular i cannot see any margins and elevation)
Here is the code:
TipsFragment.java
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
FragmentActivity superActivity = super.getActivity();
lLayout = (LinearLayout) inflater.inflate(R.layout.tips_fragment, container, false);
String[] general_tips = getResources().getStringArray(R.array.general_tips);
List<String> tips = new ArrayList<>(Arrays.asList(general_tips));
tv = (TextView)lLayout.findViewById(R.id.general_tip_header);
tv.setText("Advises");
lv = (ListView)lLayout.findViewById(R.id.general_tips_list_view);
ArrayAdapter<String> itemsAdapter = new ArrayAdapter<String>(superActivity, R.layout.tip_row, tips); //the layout is tip_row
lv.setAdapter(itemsAdapter);
String[] noobs_tips = getResources().getStringArray(R.array.noob_tips);
//tips.clear();
tips.addAll(Arrays.asList(noobs_tips));
String[] pro_tips = getResources().getStringArray(R.array.pro_tips);
//tips.clear();
tips.addAll(Arrays.asList(pro_tips));
//overrideFonts(superActivity, container);
return lLayout;
}
tips_fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include android:id="@+id/general_tip_header"
layout="@layout/tips_header"/>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/general_tips_list_view"></ListView></LinearLayout>
tips_header.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:elevation="4dp"
android:gravity="center"
android:textSize="30sp"
android:text="General Problems" />
tip_row.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tip_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_margin="30dp"
android:textSize="20sp"
android:text="Test"
android:elevation="9dp"/>
Note that in tip_row.xml I have defined android:elevation
and android:layout_margin
but this two attribute are not rendered by my app.
Here you can find a screenshot: Imgur
PS: I can succesfully change the font-size or the padding, the only things that does not work are elevation and the margin for this row items. Elevation does not work either in tips_header.xml
Thanks
Upvotes: 0
Views: 189
Reputation: 5087
Try this. Add a parent RelativeLayout
to your TextView
element and set android:clipToPadding="false"
to parent.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false">
<TextView
android:id="@+id/tip_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_margin="30dp"
android:textSize="20sp"
android:text="Test"
android:elevation="9dp"/>
</RelativeLayout>
For more info check @Justin Pollard answer
Hope its helps!
Upvotes: 1