You need to understand how the Layout_weights work. These are effective only if you have more than one views. Your code is correct, just you need to add one more view. Both declared in a linear layout. The layout in which you need to have the weights applied.
View hospVyslLineAppColor = (View) view.findViewById (R.id.hospodarsky_vysledok_line_appcolor);
hospVyslLineAppcolor.setLayoutParams(new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT,
Math.abs((float)vynosy))); // see to it the value of vynosy is less than 1
View hospVyslLineAppColor1 = (View) view.findViewById (R.id.hospodarsky_vysledok_line_appcolor);
hospVyslLineAppColor1.setLayoutParams(new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT,
(1 - Math.abs((float)vynosy)))); // Will complement the weight
And re-wite your XML file:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<!-- layout_height is 0dp as height is to be set by weight factor -->
<View
android:id="@+id/hospodarsky_vysledok_line_appcolor"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.4"
android:background="#a8a8a8" />
<!-- layout_height is 0dp as height is to be set by weight factor -->
<View
android:id="@+id/hospodarsky_vysledok_line_appcolor1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.6"
android:background="#a8a8a8" />
</LinearLayout>